Return instance in on_change_with methods

This commit is contained in:
Cédric Krier committed 2023-03-26 09:49:00 +02:00
1 parent 43b1d28326
commit b9c4b8230d
80 files changed
+206 -338

No files matched your search

+1 -2
View File
@@ -429,8 +429,7 @@ class BalanceNonDeferralStart(ModelView):
@fields.depends('fiscalyear')
def on_change_with_company(self, name=None):
if self.fiscalyear:
return self.fiscalyear.company.id
return self.fiscalyear.company if self.fiscalyear else None
class BalanceNonDeferral(Wizard):
+3 -6
View File
@@ -1121,8 +1121,7 @@ class Line(MoveLineMixin, ModelSQL, ModelView):
@fields.depends('account')
def on_change_with_currency(self, name=None):
if self.account:
return self.account.currency.id
return self.account.currency if self.account else None
@classmethod
def _get_origin(cls):
@@ -1825,8 +1824,7 @@ class ReconcileLinesWriteOff(ModelView):
@fields.depends('company')
def on_change_with_currency(self, name=None):
if self.company:
return self.company.currency.id
return self.company.currency if self.company else None
class ReconcileLines(Wizard):
@@ -2227,8 +2225,7 @@ class ReconcileShow(ModelView):
@fields.depends('company')
def on_change_with_currency(self, name=None):
if self.company:
return self.company.currency.id
return self.company.currency if self.company else None
class CancelMoves(Wizard):
+1 -2
View File
@@ -95,8 +95,7 @@ class Period(Workflow, ModelSQL, ModelView):
@fields.depends('fiscalyear', '_parent_fiscalyear.company')
def on_change_with_company(self, name=None):
if self.fiscalyear:
return self.fiscalyear.company.id
return self.fiscalyear.company if self.fiscalyear else None
@classmethod
def search_company(cls, name, clause):
+9 -12
View File
@@ -182,8 +182,7 @@ class TaxCode(
@fields.depends('company')
def on_change_with_currency(self, name=None):
if self.company:
return self.company.currency.id
return self.company.currency if self.company else None
@classmethod
def get_amount(cls, codes, name):
@@ -570,11 +569,12 @@ class TaxCodeContext(ModelView):
def on_change_with_periods(self):
pool = Pool()
Period = pool.get('account.period')
periods = []
if self.method == 'fiscalyear' and self.fiscalyear:
return [
p.id for p in self.fiscalyear.periods if p.type == 'standard']
periods.extend(
p for p in self.fiscalyear.periods if p.type == 'standard')
elif self.method == 'period' and self.period:
return [self.period.id]
periods.append(self.period)
elif (self.method == 'periods'
and self.company
and self.start_period and self.end_period):
@@ -584,8 +584,7 @@ class TaxCodeContext(ModelView):
('company', '=', self.company.id),
('type', '=', 'standard'),
])
return [p.id for p in periods]
return []
return periods
class TaxTemplate(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin):
@@ -976,8 +975,7 @@ class Tax(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin):
@fields.depends('company')
def on_change_with_currency(self, name=None):
if self.company:
return self.company.currency.id
return self.company.currency if self.company else None
@classmethod
def copy(cls, taxes, default=None):
@@ -1376,13 +1374,12 @@ class TaxLine(ModelSQL, ModelView):
@fields.depends('move_line', '_parent_move_line.currency')
def on_change_with_currency(self, name=None):
if self.move_line and self.move_line.currency:
return self.move_line.currency.id
return self.move_line.currency if self.move_line else None
@fields.depends('_parent_move_line.account', 'move_line')
def on_change_with_company(self, name=None):
if self.move_line and self.move_line.account:
return self.move_line.account.company.id
return self.move_line.account.company
def get_rec_name(self, name):
name = super(TaxLine, self).get_rec_name(name)
+4 -9
View File
@@ -309,8 +309,7 @@ class Asset(Workflow, ModelSQL, ModelView):
@fields.depends('company')
def on_change_with_currency(self, name=None):
if self.company:
return self.company.currency.id
return self.company.currency if self.company else None
@fields.depends('supplier_invoice_line', 'unit')
def on_change_supplier_invoice_line(self):
@@ -350,9 +349,7 @@ class Asset(Workflow, ModelSQL, ModelView):
@fields.depends('product')
def on_change_with_unit(self):
if not self.product:
return None
return self.product.default_uom.id
return self.product.default_uom if self.product else None
@fields.depends('end_date', 'product', 'start_date')
def on_change_with_end_date(self):
@@ -759,8 +756,7 @@ class AssetLine(ModelSQL, ModelView):
@fields.depends('asset', '_parent_asset.currency')
def on_change_with_currency(self, name=None):
if self.asset:
return self.asset.currency.id
return self.asset.currency if self.asset else None
class AssetUpdateMove(ModelSQL):
@@ -964,8 +960,7 @@ class AssetRevision(ModelSQL, ModelView):
@fields.depends('asset', '_parent_asset.currency')
def on_change_with_currency(self, name=None):
if self.asset and self.asset.currency:
return self.asset.currency.id
return self.asset.currency if self.asset else None
@fields.depends('origin', 'value', 'asset', '_parent_asset.value')
def on_change_origin(self, name=None):
+7 -12
View File
@@ -183,13 +183,12 @@ class BudgetLineMixin(
@fields.depends('budget', '_parent_budget.company')
def on_change_with_company(self, name=None):
if self.budget and self.budget.company:
return self.budget.company.id
return self.budget.company if self.budget else None
@fields.depends('budget', '_parent_budget.company')
def on_change_with_currency(self, name=None):
if self.budget and self.budget.company:
return self.budget.company.currency.id
return self.budget.company.currency
@classmethod
def get_total_amount(cls, records, name):
@@ -295,8 +294,7 @@ class BudgetContext(ModelView):
@fields.depends('budget')
def on_change_with_fiscalyear(self, name=None):
if self.budget:
return self.budget.fiscalyear.id
return self.budget.fiscalyear if self.budget else None
class Budget(BudgetMixin, ModelSQL, ModelView):
@@ -501,8 +499,7 @@ class BudgetLine(BudgetLineMixin, ModelSQL, ModelView):
@fields.depends('parent', '_parent_parent.account_type')
def on_change_with_parent_account_type(self, name=None):
if self.parent and self.parent.account_type:
return self.parent.account_type.id
return self.parent.account_type if self.parent else None
@fields.depends('account_type')
def on_change_with_current_name(self, name=None):
@@ -646,17 +643,15 @@ class BudgetLinePeriod(AmountMixin, ModelSQL, ModelView):
@fields.depends('budget_line', '_parent_budget_line.company')
def on_change_with_currency(self, name=None):
if self.budget_line and self.budget_line.company:
return self.budget_line.company.currency.id
return self.budget_line.company.currency
@fields.depends(
'budget_line',
'_parent_budget_line.budget',
'_parent_budget_line._parent_budget.fiscalyear')
def on_change_with_fiscalyear(self, name=None):
if (self.budget_line
and self.budget_line.budget
and self.budget_line.budget.fiscalyear):
return self.budget_line.budget.fiscalyear.id
if self.budget_line and self.budget_line.budget:
return self.budget_line.budget.fiscalyear
@classmethod
def get_total_amount(cls, periods, name):
+7 -12
View File
@@ -476,8 +476,7 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
@fields.depends('company')
def on_change_with_company_party(self, name=None):
if self.company:
return self.company.party.id
return self.company.party if self.company else None
@fields.depends('party', 'type', 'accounting_date', 'invoice_date')
def on_change_with_account(self):
@@ -489,7 +488,7 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
account = self.party.account_receivable_used
elif self.type == 'in':
account = self.party.account_payable_used
return account.id if account else None
return account
@classmethod
def _journal_types(cls, invoice_type):
@@ -507,9 +506,7 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
'out': 'revenue',
'in': 'expense',
}.get(self.type))
journal = Journal.find(pattern)
if journal:
return journal.id
return Journal.find(pattern)
@classmethod
def order_accounting_date(cls, tables):
@@ -2195,9 +2192,9 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
@fields.depends('party', 'invoice', '_parent_invoice.party')
def on_change_with_invoice_party(self, name=None):
if self.invoice and self.invoice.party:
return self.invoice.party.id
return self.invoice.party
elif self.party:
return self.party.id
return self.party
@classmethod
def search_invoice_party(cls, name, clause):
@@ -2445,8 +2442,7 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
@fields.depends('product')
def on_change_with_product_uom_category(self, name=None):
if self.product:
return self.product.default_uom_category.id
return self.product.default_uom_category if self.product else None
@fields.depends('account', 'product', 'invoice',
'_parent_invoice.party', '_parent_invoice.type',
@@ -2794,8 +2790,7 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView):
@fields.depends('invoice', '_parent_invoice.currency')
def on_change_with_currency(self, name=None):
if self.invoice:
return self.invoice.currency.id
return self.invoice.currency if self.invoice else None
@fields.depends('tax', 'invoice', '_parent_invoice.party', 'base')
def on_change_tax(self):
+2 -5
View File
@@ -173,9 +173,7 @@ class InvoiceDeferred(Workflow, ModelSQL, ModelView):
'out': 'revenue',
'in': 'expense',
}.get(self.type))
journal = Journal.find(pattern)
if journal:
return journal.id
return Journal.find(pattern)
@fields.depends('invoice_line', 'start_date', 'company')
def on_change_invoice_line(self):
@@ -203,8 +201,7 @@ class InvoiceDeferred(Workflow, ModelSQL, ModelView):
@fields.depends('company')
def on_change_with_currency(self, name=None):
if self.company:
return self.company.currency.id
return self.company.currency if self.company else None
@classmethod
@ModelView.button
@@ -190,8 +190,7 @@ class MoveLineGroup(MoveLineMixin, ModelSQL, ModelView):
@fields.depends('account')
def on_change_with_currency(self, name=None):
if self.account:
return self.account.currency.id
return self.account.currency if self.account else None
def get_delegated_amount(self, name):
return self.amount_currency.round(
+2 -4
View File
@@ -83,8 +83,7 @@ class PartyReceptionDirectDebit(
@fields.depends('journal')
def on_change_with_company(self, name=None):
if self.journal:
return self.journal.company.id
return self.journal.company if self.journal else None
@classmethod
def search_company(cls, name, clause):
@@ -93,8 +92,7 @@ class PartyReceptionDirectDebit(
@fields.depends('journal')
def on_change_with_currency(self, name=None):
if self.journal:
return self.journal.currency.id
return self.journal.currency if self.journal else None
@classmethod
def get_process_methods(cls):
+2 -4
View File
@@ -269,8 +269,7 @@ class Group(ModelSQL, ModelView):
@fields.depends('journal')
def on_change_with_currency(self, name=None):
if self.journal:
return self.journal.currency.id
return self.journal.currency if self.journal else None
@classmethod
def search_currency(cls, name, clause):
@@ -478,8 +477,7 @@ class Payment(Workflow, ModelSQL, ModelView):
@fields.depends('journal')
def on_change_with_currency(self, name=None):
if self.journal:
return self.journal.currency.id
return self.journal.currency if self.journal else None
@classmethod
def search_currency(cls, name, clause):
+2 -4
View File
@@ -616,13 +616,11 @@ class PaymentBraintreeRefund(Workflow, ModelSQL, ModelView):
@fields.depends('payment', '_parent_payment.currency')
def on_change_with_currency(self, name=None):
if self.payment and self.payment.currency:
return self.payment.currency.id
return self.payment.currency if self.payment else None
@fields.depends('payment', '_parent_payment.company')
def on_change_with_company(self, name=None):
if self.payment and self.payment.company:
return self.payment.company.id
return self.payment.company if self.payment else None
@classmethod
def copy(cls, refunds, default=None):
+1 -1
View File
@@ -53,7 +53,7 @@ class BraintreeCustomerMethodMixin:
@fields.depends('journal')
def on_change_with_braintree_account(self, name=None):
if self.journal and self.journal.process_method == 'braintree':
return self.journal.braintree_account.id
return self.journal.braintree_account
@fields.depends('braintree_customer', 'braintree_customer_method')
def get_braintree_customer_methods(self):
+1 -2
View File
@@ -155,8 +155,7 @@ class Journal(metaclass=PoolMeta):
@fields.depends('company')
def on_change_with_company_party(self, name=None):
if self.company:
return self.company.party.id
return self.company.party if self.company else None
@staticmethod
def default_sepa_charge_bearer():
+1 -1
View File
@@ -79,7 +79,7 @@ class StripeCustomerMethodMixin:
@fields.depends('journal')
def on_change_with_stripe_account(self, name=None):
if self.journal and self.journal.process_method == 'stripe':
return self.journal.stripe_account.id
return self.journal.stripe_account
@fields.depends('stripe_customer', 'stripe_customer_source')
def get_stripe_customer_sources(self):
+2 -4
View File
@@ -765,13 +765,11 @@ class Refund(Workflow, ModelSQL, ModelView):
@fields.depends('payment', '_parent_payment.currency')
def on_change_with_currency(self, name=None):
if self.payment and self.payment.currency:
return self.payment.currency.id
return self.payment.currency if self.payment else None
@fields.depends('payment', '_parent_payment.company')
def on_change_with_company(self, name=None):
if self.payment and self.payment.company:
return self.payment.company.id
return self.payment.company if self.payment else None
@classmethod
def default_state(cls):
+1 -2
View File
@@ -340,8 +340,7 @@ class AccountRuleAccountAbstract(sequence_ordered(), ModelSQL, ModelView):
@fields.depends('rule', '_parent_rule.company')
def on_change_with_company(self, name=None):
if self.rule and self.rule.company:
return self.rule.company.id
return self.rule.company if self.rule else None
@fields.depends('rule', '_parent_rule.account_party_required')
def on_change_with_account_party_required(self, name=None):
+1 -2
View File
@@ -92,8 +92,7 @@ class Journal(DeactivableMixin, ModelSQL, ModelView):
@fields.depends('company')
def on_change_with_company_party(self, name=None):
if self.company:
return self.company.party.id
return self.company.party if self.company else None
@staticmethod
def default_validation():
+6 -8
View File
@@ -231,8 +231,7 @@ class Statement(Workflow, ModelSQL, ModelView):
@fields.depends('journal')
def on_change_with_currency(self, name=None):
if self.journal:
return self.journal.currency.id
return self.journal.currency if self.journal else None
@fields.depends('start_balance', 'end_balance')
def on_change_with_balance(self, name=None):
@@ -726,8 +725,7 @@ def origin_mixin(_states):
@fields.depends('statement', '_parent_statement.company')
def on_change_with_company(self, name=None):
if self.statement and self.statement.company:
return self.statement.company.id
return self.statement.company if self.statement else None
@classmethod
def search_company(cls, name, clause):
@@ -736,7 +734,7 @@ def origin_mixin(_states):
@fields.depends('statement', '_parent_statement.journal')
def on_change_with_currency(self, name=None):
if self.statement and self.statement.journal:
return self.statement.journal.currency.id
return self.statement.journal.currency
return Mixin
@@ -938,11 +936,11 @@ class Line(origin_mixin(_states), sequence_ordered(), ModelSQL, ModelView):
@fields.depends('origin', '_parent_origin.company')
def on_change_with_company(self, name=None):
try:
company = super(Line, self).on_change_with_company()
company = super().on_change_with_company()
except AttributeError:
company = None
if self.origin and self.origin.company:
return self.origin.company.id
if self.origin and hasattr(self.origin, 'company'):
company = self.origin.company
return company
@fields.depends('origin', '_parent_origin.statement_state')
+2 -4
View File
@@ -107,8 +107,7 @@ class StatementRule(sequence_ordered(), ModelSQL, ModelView):
@fields.depends('journal')
def on_change_with_currency(self, name=None):
if self.journal:
return self.journal.currency.id
return self.journal.currency if self.journal else None
def match(self, origin):
keywords = {}
@@ -313,8 +312,7 @@ class StatementRuleLine(sequence_ordered(), ModelSQL, ModelView):
@fields.depends('rule', '_parent_rule.company')
def on_change_with_company(self, name=None):
if self.rule and self.rule.company:
return self.rule.company.id
return self.rule.company if self.rule else None
def get_line(self, origin, keywords, **context):
pool = Pool()
+18 -29
View File
@@ -126,9 +126,8 @@ class Move(metaclass=PoolMeta):
@fields.depends('intrastat_tariff_code')
def on_change_with_intrastat_tariff_code_uom(self, name=None):
if (self.intrastat_tariff_code
and self.intrastat_tariff_code.intrastat_uom):
return self.intrastat_tariff_code.intrastat_uom.id
if self.intrastat_tariff_code:
return self.intrastat_tariff_code.intrastat_uom
@property
@fields.depends('from_location', 'shipment')
@@ -576,10 +575,8 @@ class ShipmentIn(ShipmentMixin, metaclass=PoolMeta):
@fields.depends('warehouse')
def on_change_with_intrastat_to_country(self, name=None):
if (self.warehouse
and self.warehouse.address
and self.warehouse.address.country):
return self.warehouse.address.country.id
if self.warehouse and self.warehouse.address:
return self.warehouse.address.country
class ShipmentInReturn(ShipmentMixin, metaclass=PoolMeta):
@@ -594,15 +591,13 @@ class ShipmentInReturn(ShipmentMixin, metaclass=PoolMeta):
@fields.depends('warehouse')
def on_change_with_intrastat_from_country(self, name=None):
if (self.warehouse
and self.warehouse.address
and self.warehouse.address.country):
return self.warehouse.address.country.id
if self.warehouse and self.warehouse.address:
return self.warehouse.address.country
@fields.depends('delivery_address')
def on_change_with_intrastat_to_country(self, name=None):
if self.delivery_address and self.delivery_address.country:
return self.delivery_address.country.id
if self.delivery_address:
return self.delivery_address.country
class ShipmentOut(ShipmentMixin, metaclass=PoolMeta):
@@ -617,15 +612,13 @@ class ShipmentOut(ShipmentMixin, metaclass=PoolMeta):
@fields.depends('warehouse')
def on_change_with_intrastat_from_country(self, name=None):
if (self.warehouse
and self.warehouse.address
and self.warehouse.address.country):
return self.warehouse.address.country.id
if self.warehouse and self.warehouse.address:
return self.warehouse.address.country
@fields.depends('delivery_address')
def on_change_with_intrastat_to_country(self, name=None):
if self.delivery_address and self.delivery_address.country:
return self.delivery_address.country.id
if self.delivery_address:
return self.delivery_address.country
class ShipmentOutReturn(ShipmentMixin, metaclass=PoolMeta):
@@ -645,10 +638,8 @@ class ShipmentOutReturn(ShipmentMixin, metaclass=PoolMeta):
@fields.depends('warehouse')
def on_change_with_intrastat_to_country(self, name=None):
if (self.warehouse
and self.warehouse.address
and self.warehouse.address.country):
return self.warehouse.address.country.id
if self.warehouse and self.warehouse.address:
return self.warehouse.address.country
class ShipmentInternal(ShipmentMixin, metaclass=PoolMeta):
@@ -665,17 +656,15 @@ class ShipmentInternal(ShipmentMixin, metaclass=PoolMeta):
def on_change_with_intrastat_from_country(self, name=None):
if (self.from_location
and self.from_location.warehouse
and self.from_location.warehouse.address
and self.from_location.warehouse.address.country):
return self.from_location.warehouse.address.country.id
and self.from_location.warehouse.address):
return self.from_location.warehouse.address.country
@fields.depends('to_location')
def on_change_with_intrastat_to_country(self, name=None):
if (self.to_location
and self.to_location.warehouse
and self.to_location.warehouse.address
and self.to_location.warehouse.address.country):
return self.to_location.warehouse.address.country.id
and self.to_location.warehouse.address):
return self.to_location.warehouse.address.country
class ShipmentDrop(ShipmentMixin, metaclass=PoolMeta):
+2 -4
View File
@@ -144,8 +144,7 @@ class Account(
@fields.depends('company')
def on_change_with_currency(self, name=None):
if self.company:
return self.company.currency.id
return self.company.currency if self.company else None
@fields.depends('parent', 'type',
'_parent_parent.id', '_parent_parent.root', '_parent_parent.type')
@@ -357,8 +356,7 @@ class AccountDistribution(ModelView, ModelSQL):
@fields.depends('parent', '_parent_parent.root')
def on_change_with_root(self, name=None):
if self.parent:
return self.parent.root.id
return self.parent.root if self.parent else None
class AnalyticAccountEntry(ModelView, ModelSQL):
+2 -2
View File
@@ -82,12 +82,12 @@ class Line(ModelSQL, ModelView):
@fields.depends('move_line', '_parent_move_line.account')
def on_change_with_currency(self, name=None):
if self.move_line and self.move_line.account:
return self.move_line.account.company.currency.id
return self.move_line.account.company.currency
@fields.depends('move_line', '_parent_move_line.account')
def on_change_with_company(self, name=None):
if self.move_line and self.move_line.account:
return self.move_line.account.company.id
return self.move_line.account.company
@classmethod
def search_company(cls, name, clause):
+1 -2
View File
@@ -163,8 +163,7 @@ class BudgetLine(BudgetLineMixin, ModelSQL, ModelView):
@fields.depends('budget', '_parent_budget.root')
def on_change_with_root(self, name=None):
if self.budget and self.budget.root:
return self.budget.root.id
return self.budget.root if self.budget else None
@classmethod
def _get_amount_group_key(cls, record):
+2 -3
View File
@@ -76,11 +76,10 @@ class AnalyticAccountEntry(metaclass=PoolMeta):
Asset = pool.get('account.asset')
except KeyError:
Asset = None
company = super(AnalyticAccountEntry, self).on_change_with_company(
name)
company = super().on_change_with_company(name=name)
if (isinstance(self.origin, InvoiceLine)
or (Asset and isinstance(self.origin, Asset))):
company = self.origin.company.id if self.origin.company else None
company = self.origin.company
return company
@classmethod
+2 -3
View File
@@ -46,10 +46,9 @@ class AnalyticAccountEntry(metaclass=PoolMeta):
def on_change_with_company(self, name=None):
pool = Pool()
PurchaseLine = pool.get('purchase.line')
company = super(AnalyticAccountEntry, self).on_change_with_company(
name)
company = super().on_change_with_company(name)
if isinstance(self.origin, PurchaseLine) and self.origin.purchase:
company = self.origin.purchase.company.id
company = self.origin.purchase.company
return company
@classmethod
+2 -3
View File
@@ -46,10 +46,9 @@ class AnalyticAccountEntry(metaclass=PoolMeta):
def on_change_with_company(self, name=None):
pool = Pool()
SaleLine = pool.get('sale.line')
company = super(AnalyticAccountEntry, self).on_change_with_company(
name)
company = super().on_change_with_company(name)
if isinstance(self.origin, SaleLine) and self.origin.sale:
company = self.origin.sale.company.id
company = self.origin.sale.company
return company
@classmethod
+1 -2
View File
@@ -200,8 +200,7 @@ class Carriage(sequence_ordered(), ModelSQL, ModelView):
CarrierSelection = pool.get('carrier.selection')
pattern = self._get_carrier_selection_pattern()
carriers = CarrierSelection.get_carriers(pattern)
return [c.id for c in carriers]
return CarrierSelection.get_carriers(pattern)
@fields.depends('from_', 'to')
def _get_carrier_selection_pattern(self):
+1 -2
View File
@@ -68,8 +68,7 @@ class Carriage(sequence_ordered(), ShipmentCostMixin, ModelSQL, ModelView):
@fields.depends('shipment')
def on_change_with_company(self, name=None):
if self.shipment and self.shipment.company:
return self.shipment.company.id
return self.shipment.company if self.shipment else None
def get_rec_name(self, name):
return f'{self.carrier.rec_name} @ {self.shipment.rec_name}'
+1 -2
View File
@@ -115,5 +115,4 @@ class WeightPriceList(ModelSQL, ModelView):
@fields.depends('carrier', '_parent_carrier.weight_currency')
def on_change_with_currency(self, name=None):
if self.carrier and self.carrier.weight_currency:
return self.carrier.weight_currency.id
return self.carrier.weight_currency if self.carrier else None
+2 -4
View File
@@ -186,8 +186,7 @@ class AgentSelection(sequence_ordered(), MatchMixin, ModelSQL, ModelView):
@fields.depends('agent', '_parent_agent.company')
def on_change_with_company(self, name=None):
if self.agent:
return self.agent.company.id
return self.agent.company if self.agent else None
@classmethod
def search_company(cls, name, clause):
@@ -409,8 +408,7 @@ class Commission(ModelSQL, ModelView):
@fields.depends('agent')
def on_change_with_currency(self, name=None):
if self.agent:
return self.agent.currency.id
return self.agent.currency if self.agent else None
@fields.depends('agent')
def on_change_with_type_(self, name=None):
+1 -1
View File
@@ -91,7 +91,7 @@ class IncotermAvailableMixin(IncotermMixin):
else:
party_incoterms = set()
return [
i.id for i in incoterms
i for i in incoterms
if not party_incoterms or i in party_incoterms]
@fields.depends()
+1 -2
View File
@@ -241,8 +241,7 @@ class Template(
@fields.depends('default_uom')
def on_change_with_default_uom_category(self, name=None):
if self.default_uom:
return self.default_uom.category.id
return self.default_uom.category if self.default_uom else None
@classmethod
def search_default_uom_category(cls, name, clause):
-2
View File
@@ -223,6 +223,4 @@ class ShipmentInternal(metaclass=PoolMeta):
if not location and self.company and self.company.cost_price_warehouse:
location = Config(1).get_multivalue(
'shipment_internal_transit', company=self.company)
if location:
location = location.id
return location
+1 -2
View File
@@ -47,8 +47,7 @@ class Image(metaclass=PoolMeta):
@fields.depends('template', '_parent_template.attribute_set')
def on_change_with_attribute_set(self, name=None):
if self.template and self.template.attribute_set:
return self.template.attribute_set.id
return self.template.attribute_set if self.template else None
@fields.depends('attribute_set', 'attributes')
def on_change_with_attributes_name(self, name=None):
+1 -2
View File
@@ -188,8 +188,7 @@ class ComponentMixin(sequence_ordered(), ModelStorage):
@fields.depends('product')
def on_change_with_product_unit_category(self, name=None):
if self.product:
return self.product.default_uom.category.id
return self.product.default_uom.category if self.product else None
def get_line(self, Line, quantity, unit, **values):
pool = Pool()
+2 -2
View File
@@ -80,7 +80,7 @@ class MoveSale(metaclass=PoolMeta):
# Use getattr as reference field can have negative id
if (isinstance(self.origin, SaleLineComponent)
and getattr(self.origin, 'unit', None)):
category = self.origin.unit.category.id
category = self.origin.unit.category
return category
def get_cost_price(self, product_cost_price=None):
@@ -199,7 +199,7 @@ class MovePurchase(metaclass=PoolMeta):
# Use getattr as reference field can have negative id
if (isinstance(self.origin, PurchaseLineComponent)
and getattr(self.origin, 'unit', None)):
category = self.origin.unit.category.id
category = self.origin.unit.category
return category
@property
+1 -2
View File
@@ -89,8 +89,7 @@ class BOMInput(ModelSQL, ModelView):
@fields.depends('product')
def on_change_with_uom_category(self, name=None):
if self.product:
return self.product.default_uom.category.id
return self.product.default_uom.category if self.product else None
def get_rec_name(self, name):
return self.product.rec_name
+1 -2
View File
@@ -432,8 +432,7 @@ class Production(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
@fields.depends('product')
def on_change_with_uom_category(self, name=None):
if self.product:
return self.product.default_uom.category.id
return self.product.default_uom.category if self.product else None
@fields.depends(methods=['explode_bom'])
def on_change_bom(self):
+2 -2
View File
@@ -83,9 +83,9 @@ class Move(metaclass=PoolMeta):
'production_output', '_parent_production_output.id')
def on_change_with_production(self, name=None):
if self.production_input:
return self.production_input.id
return self.production_input
elif self.production_output:
return self.production_output.id
return self.production_output
def set_effective_date(self):
if not self.effective_date and self.production_input:
+2 -4
View File
@@ -171,8 +171,7 @@ class Work(sequence_ordered(), ModelSQL, ModelView):
@fields.depends('operation')
def on_change_with_work_center_category(self, name=None):
if self.operation and self.operation.work_center_category:
return self.operation.work_center_category.id
return self.operation.work_center_category if self.operation else None
@classmethod
def default_company(cls):
@@ -180,8 +179,7 @@ class Work(sequence_ordered(), ModelSQL, ModelView):
@fields.depends('production', '_parent_production.warehouse')
def on_change_with_warehouse(self, name=None):
if self.production:
return self.production.warehouse.id
return self.production.warehouse if self.production else None
@classmethod
def default_state(cls):
+1 -2
View File
@@ -170,8 +170,7 @@ class Work(metaclass=PoolMeta):
@fields.depends('company')
def on_change_with_currency(self, name=None):
if self.company:
return self.company.currency.id
return self.company.currency if self.company else None
@fields.depends('product', 'company')
def on_change_product(self):
+1 -1
View File
@@ -120,7 +120,7 @@ class InvoiceLine(metaclass=PoolMeta):
# Use getattr as reference field can have negative id
if (isinstance(self.origin, PurchaseLine)
and getattr(self.origin, 'unit', None)):
category = self.origin.unit.category.id
category = self.origin.unit.category
return category
def get_warehouse(self, name):
+5 -8
View File
@@ -409,11 +409,9 @@ class ProductSupplier(
'template', '_parent_template.purchase_uom')
def on_change_with_uom(self, name=None):
if self.product:
if self.product.purchase_uom:
return self.product.purchase_uom.id
return self.product.purchase_uom
elif self.template:
if self.template.purchase_uom:
return self.template.purchase_uom.id
return self.template.purchase_uom
@property
def lead_time_used(self):
@@ -506,13 +504,12 @@ class ProductSupplierPrice(
@fields.depends('product_supplier', '_parent_product_supplier.product')
def on_change_with_uom(self, name=None):
if self.product_supplier and self.product_supplier.uom:
return self.product_supplier.uom.id
return self.product_supplier.uom if self.product_supplier else None
@fields.depends('product_supplier', '_parent_product_supplier.currency')
def on_change_with_currency(self, name=None):
if self.product_supplier and self.product_supplier.currency:
return self.product_supplier.currency.id
if self.product_supplier:
return self.product_supplier.currency
@staticmethod
def get_pattern():
+5 -10
View File
@@ -1480,8 +1480,7 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
@fields.depends('product')
def on_change_with_product_uom_category(self, name=None):
if self.product:
return self.product.default_uom_category.id
return self.product.default_uom_category if self.product else None
@fields.depends(methods=['compute_unit_price'])
def on_change_quantity(self):
@@ -1526,8 +1525,7 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
@fields.depends('purchase', '_parent_purchase.warehouse')
def on_change_with_warehouse(self, name=None):
if self.purchase and self.purchase.warehouse:
return self.purchase.warehouse.id
return self.purchase.warehouse if self.purchase else None
def get_from_location(self, name):
if (self.quantity or 0) >= 0:
@@ -1619,13 +1617,11 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
@fields.depends('purchase', '_parent_purchase.company')
def on_change_with_company(self, name=None):
if self.purchase and self.purchase.company:
return self.purchase.company.id
return self.purchase.company if self.purchase else None
@fields.depends('purchase', '_parent_purchase.party')
def on_change_with_supplier(self, name=None):
if self.purchase and self.purchase.party:
return self.purchase.party.id
return self.purchase.party if self.purchase else None
@classmethod
def search_supplier(cls, name, clause):
@@ -1647,8 +1643,7 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
@fields.depends('purchase', '_parent_purchase.currency')
def on_change_with_currency(self, name=None):
if self.purchase and self.purchase.currency:
return self.purchase.currency.id
return self.purchase.currency if self.purchase else None
def get_invoice_line(self):
'Return a list of invoice line for purchase line'
+1 -1
View File
@@ -224,7 +224,7 @@ class Move(metaclass=PoolMeta):
# Use getattr as reference field can have negative id
if (isinstance(self.origin, PurchaseLine)
and getattr(self.origin, 'unit', None)):
category = self.origin.unit.category.id
category = self.origin.unit.category
return category
@property
+3 -4
View File
@@ -360,8 +360,7 @@ class AmendmentLine(ModelSQL, ModelView):
'amendment',
'_parent_amendment.purchase')
def on_change_with_purchase(self, name=None):
if self.amendment and self.amendment.purchase:
return self.amendment.purchase.id
return self.amendment.purchase if self.amendment else None
@fields.depends('line')
def on_change_line(self):
@@ -396,9 +395,9 @@ class AmendmentLine(ModelSQL, ModelView):
def on_change_with_product_uom_category(self, name=None):
if self.line:
if self.line.product_uom_category:
return self.line.product_uom_category.id
return self.line.product_uom_category
elif self.line.unit:
return self.line.unit.category.id
return self.line.unit.category
def apply(self, purchase):
assert self.purchase == purchase
@@ -552,8 +552,7 @@ class BlanketAgreementLine(ModelSQL, ModelView):
@fields.depends('product')
def on_change_with_product_uom_category(self, name=None):
if self.product:
return self.product.default_uom_category.id
return self.product.default_uom_category if self.product else None
@fields.depends(
'quantity', 'unit_price', 'blanket_agreement',
@@ -569,8 +568,8 @@ class BlanketAgreementLine(ModelSQL, ModelView):
@fields.depends('blanket_agreement', '_parent_blanket_agreement.currency')
def on_change_with_currency(self, name=None):
if self.blanket_agreement and self.blanket_agreement.currency:
return self.blanket_agreement.currency.id
if self.blanket_agreement:
return self.blanket_agreement.currency
def get_processed_quantity(self, name=None):
processed_quantity = 0.
@@ -598,8 +597,8 @@ class BlanketAgreementLine(ModelSQL, ModelView):
@fields.depends('blanket_agreement', '_parent_blanket_agreement.company')
def on_change_with_company(self, name=None):
if self.blanket_agreement and self.blanket_agreement.company:
return self.blanket_agreement.company.id
if self.blanket_agreement:
return self.blanket_agreement.company
def get_purchase_line(self, purchase):
pool = Pool()
+2 -4
View File
@@ -291,13 +291,11 @@ class PurchaseRequest(ModelSQL, ModelView):
@fields.depends('product')
def on_change_with_product_uom_category(self, name=None):
if self.product:
return self.product.default_uom_category.id
return self.product.default_uom_category if self.product else None
@fields.depends('product')
def on_change_with_default_uom(self, name=None):
if self.product:
return self.product.default_uom.id
return self.product.default_uom if self.product else None
@fields.depends('product')
def on_change_with_default_uom_digits(self, name=None):
@@ -361,8 +361,7 @@ class QuotationLine(ModelSQL, ModelView):
@fields.depends('product')
def on_change_with_product_uom_category(self, name=None):
if self.product:
return self.product.default_uom_category.id
return self.product.default_uom_category if self.product else None
@classmethod
def get_quotation_state(cls):
+2 -4
View File
@@ -496,13 +496,11 @@ class PurchaseRequisitionLine(sequence_ordered(), ModelSQL, ModelView):
@fields.depends('product')
def on_change_with_product_uom_category(self, name=None):
if self.product:
return self.product.default_uom_category.id
return self.product.default_uom_category if self.product else None
@fields.depends('requisition', '_parent_requisition.currency')
def on_change_with_currency(self, name=None):
if self.requisition and self.requisition.currency:
return self.requisition.currency.id
return self.requisition.currency if self.requisition else None
@classmethod
def get_purchase_requisition_states(cls):
+3 -3
View File
@@ -59,7 +59,7 @@ class PurchaseSecondaryMixin:
@fields.depends('purchase_secondary_uom')
def on_change_with_purchase_secondary_uom_category(self, name=None):
if self.purchase_secondary_uom:
return self.purchase_secondary_uom.category.id
return self.purchase_secondary_uom.category
@classmethod
def search_purchase_secondary_uom_category(cls, name, clause):
@@ -155,9 +155,9 @@ class ProductSupplier(PurchaseSecondaryMixin, metaclass=PoolMeta):
'product', '_parent_product.purchase_uom')
def on_change_with_default_uom_category(self, name=None):
if self.product and self.product.purchase_uom:
return self.product.purchase_uom.category.id
return self.product.purchase_uom.category
elif self.template and self.template.purchase_uom:
return self.template.purchase_uom.category.id
return self.template.purchase_uom.category
@property
def purchase_uom(self):
+3 -3
View File
@@ -124,7 +124,7 @@ class Line(metaclass=PoolMeta):
def on_change_with_product_secondary_uom_category(self, name=None):
secondary_record = self._secondary_record()
if secondary_record:
return secondary_record.purchase_secondary_uom.category.id
return secondary_record.purchase_secondary_uom.category
@classmethod
def set_secondary(cls, lines, name, value):
@@ -186,7 +186,7 @@ class RequisitionLine(metaclass=PoolMeta):
@fields.depends('product')
def on_change_with_product_secondary_uom_category(self, name=None):
if self.product and self.product.purchase_secondary_uom:
return self.product.purchase_secondary_uom.category.id
return self.product.purchase_secondary_uom.category
@property
def request_unit(self):
@@ -275,7 +275,7 @@ class BlanketAgreementLine(metaclass=PoolMeta):
@fields.depends('product')
def on_change_with_product_secondary_uom_category(self, name=None):
if self.product and self.product.purchase_secondary_uom:
return self.product.purchase_secondary_uom.category.id
return self.product.purchase_secondary_uom.category
def _set_purchase_line_quantity(self, purchase_line):
super()._set_purchase_line_quantity(purchase_line)
+1 -1
View File
@@ -118,7 +118,7 @@ class Line(metaclass=PoolMeta):
# Use getattr as reference field can have negative id
if (isinstance(self.origin, SaleLine)
and getattr(self.origin, 'unit', None)):
category = self.origin.unit.category.id
category = self.origin.unit.category
return category
def get_warehouse(self, name):
+5 -10
View File
@@ -1496,8 +1496,7 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView):
@fields.depends('product')
def on_change_with_product_uom_category(self, name=None):
if self.product:
return self.product.default_uom_category.id
return self.product.default_uom_category if self.product else None
@fields.depends(methods=['compute_unit_price'])
def on_change_quantity(self):
@@ -1546,8 +1545,7 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView):
@fields.depends('sale', '_parent_sale.warehouse')
def on_change_with_warehouse(self, name=None):
if self.sale and self.sale.warehouse:
return self.sale.warehouse.id
return self.sale.warehouse if self.sale else None
def get_from_location(self, name):
if (self.quantity or 0) >= 0:
@@ -1600,8 +1598,7 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView):
@fields.depends('sale', '_parent_sale.currency')
def on_change_with_currency(self, name=None):
if self.sale and self.sale.currency:
return self.sale.currency.id
return self.sale.currency if self.sale else None
@classmethod
def get_sale_states(cls):
@@ -1620,13 +1617,11 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView):
@fields.depends('sale', '_parent_sale.company')
def on_change_with_company(self, name=None):
if self.sale and self.sale.company:
return self.sale.company.id
return self.sale.company if self.sale else None
@fields.depends('sale', '_parent_sale.party')
def on_change_with_customer(self, name=None):
if self.sale and self.sale.party:
return self.sale.party.id
return self.sale.party if self.sale else None
@classmethod
def search_customer(cls, name, clause):
+2 -3
View File
@@ -154,14 +154,13 @@ class Move(metaclass=PoolMeta):
def on_change_with_product_uom_category(self, name=None):
pool = Pool()
SaleLine = pool.get('sale.line')
category = super(Move, self).on_change_with_product_uom_category(
name=name)
category = super().on_change_with_product_uom_category(name=name)
# Enforce the same unit category as they are used to compute the
# remaining quantity to ship and the quantity to invoice.
# Use getattr as reference field can have negative id
if (isinstance(self.origin, SaleLine)
and getattr(self.origin, 'unit', None)):
category = self.origin.unit.category.id
category = self.origin.unit.category
return category
def get_cost_price(self, product_cost_price=None):
+2 -4
View File
@@ -200,13 +200,11 @@ class AdvancePaymentCondition(ModelSQL, ModelView):
@fields.depends('sale', '_parent_sale.company')
def on_change_with_sale_company(self, name=None):
if self.sale and self.sale.company:
return self.sale.company.id
return self.sale.company if self.sale else None
@fields.depends('sale', '_parent_sale.currency')
def on_change_with_currency(self, name=None):
if self.sale and self.sale.currency:
return self.sale.currency.id
return self.sale.currency if self.sale else None
@classmethod
def copy(cls, conditions, default=None):
+3 -4
View File
@@ -385,8 +385,7 @@ class AmendmentLine(ModelSQL, ModelView):
'amendment',
'_parent_amendment.sale')
def on_change_with_sale(self, name=None):
if self.amendment and self.amendment.sale:
return self.amendment.sale.id
return self.amendment.sale if self.amendment else None
@fields.depends('line')
def on_change_line(self):
@@ -438,9 +437,9 @@ class AmendmentLine(ModelSQL, ModelView):
def on_change_with_product_uom_category(self, name=None):
if self.line:
if self.line.product_uom_category:
return self.line.product_uom_category.id
return self.line.product_uom_category
elif self.line.unit:
return self.line.unit.category.id
return self.line.unit.category
def apply(self, sale):
assert self.sale == sale
+5 -6
View File
@@ -505,8 +505,7 @@ class BlanketAgreementLine(ModelSQL, ModelView):
@fields.depends('product')
def on_change_with_product_uom_category(self, name=None):
if self.product:
return self.product.default_uom_category.id
return self.product.default_uom_category if self.product else None
@fields.depends(
'quantity', 'unit_price', 'blanket_agreement',
@@ -522,8 +521,8 @@ class BlanketAgreementLine(ModelSQL, ModelView):
@fields.depends('blanket_agreement', '_parent_blanket_agreement.currency')
def on_change_with_currency(self, name=None):
if self.blanket_agreement and self.blanket_agreement.currency:
return self.blanket_agreement.currency.id
if self.blanket_agreement:
return self.blanket_agreement.currency
def get_processed_quantity(self, name=None):
processed_quantity = 0.
@@ -551,8 +550,8 @@ class BlanketAgreementLine(ModelSQL, ModelView):
@fields.depends('blanket_agreement', '_parent_blanket_agreement.company')
def on_change_with_company(self, name=None):
if self.blanket_agreement and self.blanket_agreement.company:
return self.blanket_agreement.company.id
if self.blanket_agreement:
return self.blanket_agreement.company
def get_sale_line(self, sale):
pool = Pool()
+5 -8
View File
@@ -459,7 +459,7 @@ class Action(ModelSQL, ModelView):
if (self.complaint
and self.complaint.origin_model in {
'sale.line', 'account.invoice.line'}):
return self.complaint.origin.unit.id
return self.complaint.origin.unit
@fields.depends(
'quantity', 'unit_price', 'currency', 'sale_lines', 'invoice_lines',
@@ -506,7 +506,7 @@ class Action(ModelSQL, ModelView):
and self.complaint.origin_model in {
'sale.sale', 'sale.line',
'account.invoice', 'account.invoice.line'}):
return self.complaint.origin.currency.id
return self.complaint.origin.currency
@classmethod
def get_complaint_states(cls):
@@ -706,8 +706,7 @@ class _Action_Line:
@fields.depends('action', '_parent_action.currency')
def on_change_with_currency(self, name=None):
if self.action and self.action.currency:
return self.action.currency.id
return self.action.currency if self.action else None
@classmethod
def get_complaint_states(cls):
@@ -742,8 +741,7 @@ class Action_SaleLine(_Action_Line, ModelView, ModelSQL):
@fields.depends('line')
def on_change_with_unit(self, name=None):
if self.line and self.line.unit:
return self.line.unit.id
return self.line.unit if self.line else None
@fields.depends('quantity', 'line')
def get_quantity(self):
@@ -774,8 +772,7 @@ class Action_InvoiceLine(_Action_Line, ModelView, ModelSQL):
@fields.depends('line')
def on_change_with_unit(self, name=None):
if self.line and self.line.unit:
return self.line.unit.id
return self.line.unit if self.line else None
@fields.depends('quantity', 'line')
def get_quantity(self):
+3 -6
View File
@@ -131,8 +131,7 @@ class Extra(DeactivableMixin, ModelSQL, ModelView, MatchMixin):
@fields.depends('company')
def on_change_with_currency(self, name=None):
if self.company:
return self.company.currency.id
return self.company.currency if self.company else None
@classmethod
def _extras_domain(cls, sale):
@@ -216,8 +215,7 @@ class ExtraLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin):
@fields.depends('product')
def on_change_with_product_uom_category(self, name=None):
if self.product:
return self.product.default_uom_category.id
return self.product.default_uom_category if self.product else None
@fields.depends('product')
def on_change_product(self):
@@ -230,8 +228,7 @@ class ExtraLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin):
@fields.depends('extra', '_parent_extra.currency')
def on_change_with_currency(self, name=None):
if self.extra and self.extra.currency:
return self.extra.currency.id
return self.extra.currency if self.extra else None
def match(self, pattern):
pattern = pattern.copy()
+1 -1
View File
@@ -552,4 +552,4 @@ class POSPayGiftCard(ModelView):
@fields.depends('sale')
def on_change_with_currency(self, name=None):
if self.sale and self.sale.company:
return self.sale.company.currency.id
return self.sale.company.currency
+10 -20
View File
@@ -235,8 +235,7 @@ class POSSale(Workflow, ModelSQL, ModelView, TaxableMixin):
@fields.depends('company')
def on_change_with_currency(self, name=None):
if self.company and self.company.currency:
return self.company.currency.id
return self.company.currency if self.company else None
@fields.depends('lines')
def on_change_with_total_tax(self, name=None):
@@ -512,8 +511,7 @@ class POSSaleLine(ModelSQL, ModelView, TaxableMixin):
@fields.depends('product')
def on_change_with_unit(self, name=None):
# TODO packaging UOM
if self.product:
return self.product.sale_uom.id
return self.product.sale_uom if self.product else None
@classmethod
def get_sale_states(cls):
@@ -576,8 +574,7 @@ class POSSaleLine(ModelSQL, ModelView, TaxableMixin):
@fields.depends('sale', '_parent_sale.company')
def on_change_with_company(self, name=None):
if self.sale and self.sale.company:
return self.sale.company.id
return self.sale.company if self.sale else None
@classmethod
def search_company(cls, name, clause):
@@ -585,8 +582,7 @@ class POSSaleLine(ModelSQL, ModelView, TaxableMixin):
@fields.depends('sale', '_parent_sale.currency')
def on_change_with_currency(self, name=None):
if self.sale and self.sale.currency:
return self.sale.currency.id
return self.sale.currency if self.sale else None
@property
def untax_amount(self):
@@ -877,8 +873,7 @@ class POSCashSession(Workflow, ModelSQL, ModelView):
@fields.depends('point')
def on_change_with_currency(self, name=None):
if self.point:
return self.point.company.currency.id
return self.point.company.currency if self.point else None
@classmethod
@Workflow.transition('open')
@@ -1022,13 +1017,11 @@ class POSPayment(ModelSQL, ModelView):
@fields.depends('company')
def on_change_with_currency(self, name=None):
if self.company and self.company.currency:
return self.company.currency.id
return self.company.currency if self.company else None
@fields.depends('sale', '_parent_sale.company')
def on_change_with_company(self, name=None):
if self.sale and self.sale.company:
return self.sale.company.id
return self.sale.company if self.sale else None
@classmethod
def search_company(cls, name, clause):
@@ -1047,8 +1040,7 @@ class POSPayment(ModelSQL, ModelView):
@fields.depends('sale', '_parent_sale.point')
def on_change_with_point(self, name=None):
if self.sale and self.sale.point:
return self.sale.point.id
return self.sale.point if self.sale else None
@fields.depends('method')
def on_change_with_cash(self, name=None):
@@ -1253,13 +1245,11 @@ class POSCashTransfer(Workflow, ModelSQL, ModelView):
@fields.depends('point')
def on_change_with_company(self, name=None):
if self.point:
return self.point.company.id
return self.point.company if self.point else None
@fields.depends('point')
def on_change_with_currency(self, name=None):
if self.point:
return self.point.company.currency.id
return self.point.company.currency if self.point else None
@classmethod
def delete(cls, transfers):
+4 -4
View File
@@ -82,14 +82,14 @@ class SaleMixin:
config = Configuration(1)
method = config.get_multivalue('product_recommendation_method')
size = config.get_multivalue('product_recommendation_size')
product_ids = []
products = []
if method:
products = getattr(self, '_recommended_products_%s' % method)()
for product in filter(self._is_recommendable_product, products):
product_ids.append(product.id)
if len(product_ids) >= size:
products.append(product)
if len(products) >= size:
break
return product_ids
return products
@classmethod
def _is_recommendable_product(cls, product):
+1 -1
View File
@@ -199,7 +199,7 @@ class Sale(metaclass=PoolMeta):
@fields.depends(methods=['_coupon_parties'])
def on_change_with_coupon_parties(self, name=None):
return [p.id for p in self._coupon_parties()]
return list(self._coupon_parties())
@fields.depends('party')
def _coupon_parties(self):
+3 -3
View File
@@ -56,7 +56,7 @@ class SaleSecondaryMixin:
@fields.depends('sale_secondary_uom')
def on_change_with_sale_secondary_uom_category(self, name=None):
if self.sale_secondary_uom:
return self.sale_secondary_uom.category.id
return self.sale_secondary_uom.category
@classmethod
def search_sale_secondary_uom_category(cls, name, clause):
@@ -151,9 +151,9 @@ class ProductCustomer(SaleSecondaryMixin, metaclass=PoolMeta):
'product', '_parent_product.sale_uom')
def on_change_with_default_uom_category(self, name=None):
if self.product and self.product.sale_uom:
return self.product.sale_uom.category.id
return self.product.sale_uom.category
elif self.template and self.template.sale_uom:
return self.template.sale_uom.category.id
return self.template.sale_uom.category
@property
def sale_uom(self):
+2 -2
View File
@@ -121,7 +121,7 @@ class Line(metaclass=PoolMeta):
def on_change_with_product_secondary_uom_category(self, name=None):
secondary_record = self._secondary_record()
if secondary_record:
return secondary_record.sale_secondary_uom.category.id
return secondary_record.sale_secondary_uom.category
@classmethod
def set_secondary(cls, lines, name, value):
@@ -226,7 +226,7 @@ class BlanketAgreementLine(metaclass=PoolMeta):
@fields.depends('product')
def on_change_with_product_secondary_uom_category(self, name=None):
if self.product and self.product.sale_secondary_uom:
return self.product.sale_secondary_uom.category.id
return self.product.sale_secondary_uom.category
def _set_sale_line_quantity(self, sale_line):
super()._set_sale_line_quantity(sale_line)
+1 -2
View File
@@ -154,8 +154,7 @@ class Sale(metaclass=PoolMeta):
return []
pattern = self._get_carrier_selection_pattern()
carriers = CarrierSelection.get_carriers(pattern)
return [c.id for c in carriers]
return CarrierSelection.get_carriers(pattern)
@fields.depends('carrier', methods=['on_change_with_available_carriers'])
def on_change_party(self):
+1 -1
View File
@@ -87,7 +87,7 @@ class ShipmentCostSaleMixin:
if not self.cost_edit and not self.shipment_cost_sale_readonly:
return self._compute_costs()['cost_sale_currency']
elif self.cost_sale_currency:
return self.cost_sale_currency.id
return self.cost_sale_currency
@classmethod
def get_cost_methods(cls):
+4 -7
View File
@@ -666,8 +666,7 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
@fields.depends('subscription', '_parent_subscription.company')
def on_change_with_company(self, name=None):
if self.subscription and self.subscription.company:
return self.subscription.company.id
return self.subscription.company if self.subscription else None
@fields.depends('subscription', 'start_date', 'end_date',
'_parent_subscription.start_date', '_parent_subscription.end_date')
@@ -684,13 +683,12 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
@fields.depends('subscription', '_parent_subscription.currency')
def on_change_with_currency(self, name=None):
if self.subscription and self.subscription.currency:
return self.subscription.currency.id
return self.subscription.currency if self.subscription else None
@fields.depends('service')
def on_change_with_service_unit_category(self, name=None):
if self.service:
return self.service.product.default_uom_category.id
return self.service.product.default_uom_category
@fields.depends('service', 'quantity', 'unit',
'subscription', '_parent_subscription.party',
@@ -908,8 +906,7 @@ class LineConsumption(ModelSQL, ModelView):
@fields.depends('line')
def on_change_with_unit(self, name=None):
if self.line and self.line.unit:
return self.line.unit.id
return self.line.unit if self.line else None
@classmethod
def copy(cls, consumptions, default=None):
+1 -2
View File
@@ -412,8 +412,7 @@ class InventoryLine(ModelSQL, ModelView):
@fields.depends('inventory', '_parent_inventory.location')
def on_change_with_inventory_location(self, name=None):
if self.inventory and self.inventory.location:
return self.inventory.location.id
return self.inventory.location if self.inventory else None
@classmethod
def search_inventory_location(cls, name, clause):
+1 -2
View File
@@ -424,8 +424,7 @@ class Move(Workflow, ModelSQL, ModelView):
@fields.depends('product')
def on_change_with_product_uom_category(self, name=None):
if self.product:
return self.product.default_uom_category.id
return self.product.default_uom_category if self.product else None
@classmethod
def get_unit_price_company(cls, moves, name):
+6 -11
View File
@@ -400,8 +400,7 @@ class ShipmentIn(ShipmentMixin, Workflow, ModelSQL, ModelView):
@fields.depends('supplier')
def on_change_with_supplier_location(self, name=None):
if self.supplier and self.supplier.supplier_location:
return self.supplier.supplier_location.id
return self.supplier.supplier_location if self.supplier else None
def get_incoming_moves(self, name):
moves = sort(self.moves, self.__class__.incoming_moves.order)
@@ -820,8 +819,7 @@ class ShipmentInReturn(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
@fields.depends('from_location')
def on_change_with_warehouse(self, name=None):
if self.from_location and self.from_location.warehouse:
return self.from_location.warehouse.id
return self.from_location.warehouse if self.from_location else None
@property
def _move_planned_date(self):
@@ -1350,8 +1348,7 @@ class ShipmentOut(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
@fields.depends('customer')
def on_change_with_customer_location(self, name=None):
if self.customer:
return self.customer.customer_location.id
return self.customer.customer_location if self.customer else None
def get_outgoing_moves(self, name):
moves = sort(self.moves, self.__class__.outgoing_moves.order)
@@ -2008,8 +2005,7 @@ class ShipmentOutReturn(ShipmentMixin, Workflow, ModelSQL, ModelView):
@fields.depends('customer')
def on_change_with_customer_location(self, name=None):
if self.customer:
return self.customer.customer_location.id
return self.customer.customer_location if self.customer else None
def get_incoming_moves(self, name):
moves = sort(self.moves, self.__class__.incoming_moves.order)
@@ -2534,12 +2530,11 @@ class ShipmentInternal(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
and self.to_location.warehouse):
return Config(1).get_multivalue(
'shipment_internal_transit',
company=self.company.id if self.company else None).id
company=self.company.id if self.company else None)
@fields.depends('from_location')
def on_change_with_warehouse(self, name=None):
if self.from_location and self.from_location.warehouse:
return self.from_location.warehouse.id
return self.from_location.warehouse if self.from_location else None
@fields.depends(
'planned_date', 'from_location', 'to_location',
+1 -2
View File
@@ -408,8 +408,7 @@ class ShipmentAssignedMove(ModelView):
@fields.depends('move')
def on_change_with_unit(self, name=None):
if self.move:
return self.move.uom.id
return self.move.uom if self.move else None
@fields.depends('move')
def on_change_with_move_quantity(self, name=None):
+1 -2
View File
@@ -355,8 +355,7 @@ class ForecastLine(ModelSQL, ModelView):
@fields.depends('product')
def on_change_with_product_uom_category(self, name=None):
if self.product:
return self.product.default_uom_category.id
return self.product.default_uom_category if self.product else None
@classmethod
def get_forecast_states(cls):
+2 -3
View File
@@ -123,8 +123,7 @@ class Lot(DeactivableMixin, ModelSQL, ModelView, LotMixin, StockMixin):
@fields.depends('product')
def on_change_with_default_uom(self, name=None):
if self.product:
return self.product.default_uom.id
return self.product.default_uom if self.product else None
@fields.depends('product')
def on_change_with_default_uom_digits(self, name=None):
@@ -381,7 +380,7 @@ class LotByWarehouseContext(LotByLocationContext):
def on_change_with_locations(self, name=None):
locations = []
if self.warehouse:
locations.append(self.warehouse.id)
locations.append(self.warehouse)
return locations
+1 -2
View File
@@ -49,8 +49,7 @@ class LotUnitMixin:
@fields.depends('product')
def on_change_with_product_default_uom_category(self, name=None):
if self.product:
category = self.product.default_uom_category
return category.id if category else None
return self.product.default_uom_category
class Lot(LotUnitMixin, metaclass=PoolMeta):
@@ -204,12 +204,10 @@ class QuantityEarlyPlan(Workflow, ModelSQL, ModelView):
pool = Pool()
Move = pool.get('stock.move')
if isinstance(self.origin, Move) and self.origin.id >= 0:
warehouse = self.origin.from_location.warehouse
if warehouse:
return warehouse.id
return self.origin.from_location.warehouse
elif (isinstance(self.origin, Model) and self.origin.id >= 0
and getattr(self.origin, 'warehouse', None)):
return self.origin.warehouse.id
and hasattr(self.origin, 'warehouse')):
return self.origin.warehouse
def get_moves(self, name):
pool = Pool()
+2 -2
View File
@@ -146,8 +146,8 @@ class QuantityIssue(
@fields.depends('origin')
def on_change_with_warehouse(self, name=None):
if (isinstance(self.origin, Model) and self.origin.id >= 0
and getattr(self.origin, 'warehouse', None)):
return self.origin.warehouse.id
and hasattr(self.origin, 'warehouse')):
return self.origin.warehouse
@classmethod
def default_state(cls):
+1 -1
View File
@@ -104,7 +104,7 @@ class ShipmentCostMixin:
if not self.cost_edit and not readonly:
return self._compute_costs()['cost_currency']
elif self.cost_currency:
return self.cost_currency.id
return self.cost_currency
@fields.depends(
'cost', 'cost_edit',