diff --git a/modules/account/fiscalyear.py b/modules/account/fiscalyear.py index 5d3078729b..0c5a9c726d 100644 --- a/modules/account/fiscalyear.py +++ b/modules/account/fiscalyear.py @@ -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): diff --git a/modules/account/move.py b/modules/account/move.py index 3e92d2d30c..a13183dc84 100644 --- a/modules/account/move.py +++ b/modules/account/move.py @@ -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): diff --git a/modules/account/period.py b/modules/account/period.py index fed3efdc13..da9305141d 100644 --- a/modules/account/period.py +++ b/modules/account/period.py @@ -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): diff --git a/modules/account/tax.py b/modules/account/tax.py index 294a3a0f6d..5c13e8e53e 100644 --- a/modules/account/tax.py +++ b/modules/account/tax.py @@ -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) diff --git a/modules/account_asset/asset.py b/modules/account_asset/asset.py index e016f4b0fc..dad0d9151c 100644 --- a/modules/account_asset/asset.py +++ b/modules/account_asset/asset.py @@ -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): diff --git a/modules/account_budget/account.py b/modules/account_budget/account.py index 943b7cc162..8b07051f5e 100644 --- a/modules/account_budget/account.py +++ b/modules/account_budget/account.py @@ -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): diff --git a/modules/account_invoice/invoice.py b/modules/account_invoice/invoice.py index da8e3cb3df..5f879c3831 100644 --- a/modules/account_invoice/invoice.py +++ b/modules/account_invoice/invoice.py @@ -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): diff --git a/modules/account_invoice_defer/account.py b/modules/account_invoice_defer/account.py index 7d46446cbc..b24238883d 100644 --- a/modules/account_invoice_defer/account.py +++ b/modules/account_invoice_defer/account.py @@ -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 diff --git a/modules/account_move_line_grouping/account.py b/modules/account_move_line_grouping/account.py index fa3d65a0e0..d834cd9af5 100644 --- a/modules/account_move_line_grouping/account.py +++ b/modules/account_move_line_grouping/account.py @@ -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( diff --git a/modules/account_payment/party.py b/modules/account_payment/party.py index a5e7e2b21a..ceb5985c62 100644 --- a/modules/account_payment/party.py +++ b/modules/account_payment/party.py @@ -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): diff --git a/modules/account_payment/payment.py b/modules/account_payment/payment.py index 0e3049897d..31eb5079b4 100644 --- a/modules/account_payment/payment.py +++ b/modules/account_payment/payment.py @@ -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): diff --git a/modules/account_payment_braintree/account.py b/modules/account_payment_braintree/account.py index cdf9cfbdf4..d05373784c 100644 --- a/modules/account_payment_braintree/account.py +++ b/modules/account_payment_braintree/account.py @@ -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): diff --git a/modules/account_payment_braintree/common.py b/modules/account_payment_braintree/common.py index 8b3c0ae3cf..ce417ee74e 100644 --- a/modules/account_payment_braintree/common.py +++ b/modules/account_payment_braintree/common.py @@ -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): diff --git a/modules/account_payment_sepa/payment.py b/modules/account_payment_sepa/payment.py index 88f7bfa1a1..1a444fb5f9 100644 --- a/modules/account_payment_sepa/payment.py +++ b/modules/account_payment_sepa/payment.py @@ -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(): diff --git a/modules/account_payment_stripe/common.py b/modules/account_payment_stripe/common.py index a8484edf56..6bd6de27a8 100644 --- a/modules/account_payment_stripe/common.py +++ b/modules/account_payment_stripe/common.py @@ -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): diff --git a/modules/account_payment_stripe/payment.py b/modules/account_payment_stripe/payment.py index 13b1906d7b..997bb47ec5 100644 --- a/modules/account_payment_stripe/payment.py +++ b/modules/account_payment_stripe/payment.py @@ -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): diff --git a/modules/account_receivable_rule/account.py b/modules/account_receivable_rule/account.py index dd8b415926..bcab01ad8f 100644 --- a/modules/account_receivable_rule/account.py +++ b/modules/account_receivable_rule/account.py @@ -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): diff --git a/modules/account_statement/journal.py b/modules/account_statement/journal.py index fc2a48f295..5a3227b620 100644 --- a/modules/account_statement/journal.py +++ b/modules/account_statement/journal.py @@ -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(): diff --git a/modules/account_statement/statement.py b/modules/account_statement/statement.py index 7fa333ff6d..a1f11fe898 100644 --- a/modules/account_statement/statement.py +++ b/modules/account_statement/statement.py @@ -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') diff --git a/modules/account_statement_rule/account.py b/modules/account_statement_rule/account.py index d0581235e1..02e07cf318 100644 --- a/modules/account_statement_rule/account.py +++ b/modules/account_statement_rule/account.py @@ -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() diff --git a/modules/account_stock_eu/stock.py b/modules/account_stock_eu/stock.py index 46c3725551..4605d0d210 100644 --- a/modules/account_stock_eu/stock.py +++ b/modules/account_stock_eu/stock.py @@ -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): diff --git a/modules/analytic_account/account.py b/modules/analytic_account/account.py index 5eafc3c9e5..e3d08e757b 100644 --- a/modules/analytic_account/account.py +++ b/modules/analytic_account/account.py @@ -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): diff --git a/modules/analytic_account/line.py b/modules/analytic_account/line.py index b8a02875ba..bdaeef86fc 100644 --- a/modules/analytic_account/line.py +++ b/modules/analytic_account/line.py @@ -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): diff --git a/modules/analytic_budget/analytic_account.py b/modules/analytic_budget/analytic_account.py index b4c270ed08..0623f4d698 100644 --- a/modules/analytic_budget/analytic_account.py +++ b/modules/analytic_budget/analytic_account.py @@ -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): diff --git a/modules/analytic_invoice/invoice.py b/modules/analytic_invoice/invoice.py index d9c65b9852..f4d9a6fae6 100644 --- a/modules/analytic_invoice/invoice.py +++ b/modules/analytic_invoice/invoice.py @@ -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 diff --git a/modules/analytic_purchase/purchase.py b/modules/analytic_purchase/purchase.py index 270bef1b95..dcdf2a1c8f 100644 --- a/modules/analytic_purchase/purchase.py +++ b/modules/analytic_purchase/purchase.py @@ -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 diff --git a/modules/analytic_sale/sale.py b/modules/analytic_sale/sale.py index 104c4d7774..71177a34c2 100644 --- a/modules/analytic_sale/sale.py +++ b/modules/analytic_sale/sale.py @@ -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 diff --git a/modules/carrier_carriage/sale.py b/modules/carrier_carriage/sale.py index e401a58059..139954856a 100644 --- a/modules/carrier_carriage/sale.py +++ b/modules/carrier_carriage/sale.py @@ -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): diff --git a/modules/carrier_carriage/stock.py b/modules/carrier_carriage/stock.py index e11b266bf5..9a0aeedb45 100644 --- a/modules/carrier_carriage/stock.py +++ b/modules/carrier_carriage/stock.py @@ -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}' diff --git a/modules/carrier_weight/carrier.py b/modules/carrier_weight/carrier.py index 22e5e5bda6..ab02f630b6 100644 --- a/modules/carrier_weight/carrier.py +++ b/modules/carrier_weight/carrier.py @@ -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 diff --git a/modules/commission/commission.py b/modules/commission/commission.py index c70733a793..25e0142ea6 100644 --- a/modules/commission/commission.py +++ b/modules/commission/commission.py @@ -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): diff --git a/modules/incoterm/common.py b/modules/incoterm/common.py index 6fc874356d..17eb2e609d 100644 --- a/modules/incoterm/common.py +++ b/modules/incoterm/common.py @@ -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() diff --git a/modules/product/product.py b/modules/product/product.py index 70092b4470..e46f608dcb 100644 --- a/modules/product/product.py +++ b/modules/product/product.py @@ -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): diff --git a/modules/product_cost_warehouse/stock.py b/modules/product_cost_warehouse/stock.py index 30abe4c6e2..ec62bac4b5 100644 --- a/modules/product_cost_warehouse/stock.py +++ b/modules/product_cost_warehouse/stock.py @@ -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 diff --git a/modules/product_image_attribute/product.py b/modules/product_image_attribute/product.py index 9dcb433f76..e1f7c6376b 100644 --- a/modules/product_image_attribute/product.py +++ b/modules/product_image_attribute/product.py @@ -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): diff --git a/modules/product_kit/product.py b/modules/product_kit/product.py index d88df0dd50..fb33c0711e 100644 --- a/modules/product_kit/product.py +++ b/modules/product_kit/product.py @@ -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() diff --git a/modules/product_kit/stock.py b/modules/product_kit/stock.py index fe4f7c5926..12554fb8d9 100644 --- a/modules/product_kit/stock.py +++ b/modules/product_kit/stock.py @@ -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 diff --git a/modules/production/bom.py b/modules/production/bom.py index 3a51262b04..1ec6816839 100644 --- a/modules/production/bom.py +++ b/modules/production/bom.py @@ -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 diff --git a/modules/production/production.py b/modules/production/production.py index 2f991c51e5..4fba9d280a 100644 --- a/modules/production/production.py +++ b/modules/production/production.py @@ -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): diff --git a/modules/production/stock.py b/modules/production/stock.py index 8746f4193d..1be9a38bdd 100644 --- a/modules/production/stock.py +++ b/modules/production/stock.py @@ -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: diff --git a/modules/production_work/work.py b/modules/production_work/work.py index c1ad44717b..9ed47b8bfd 100644 --- a/modules/production_work/work.py +++ b/modules/production_work/work.py @@ -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): diff --git a/modules/project_revenue/work.py b/modules/project_revenue/work.py index 2d399447be..644917f3eb 100644 --- a/modules/project_revenue/work.py +++ b/modules/project_revenue/work.py @@ -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): diff --git a/modules/purchase/invoice.py b/modules/purchase/invoice.py index 8a00cbed19..e1ed67e279 100644 --- a/modules/purchase/invoice.py +++ b/modules/purchase/invoice.py @@ -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): diff --git a/modules/purchase/product.py b/modules/purchase/product.py index f34c466cbf..8367f014bd 100644 --- a/modules/purchase/product.py +++ b/modules/purchase/product.py @@ -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(): diff --git a/modules/purchase/purchase.py b/modules/purchase/purchase.py index 3a34235f39..d11149a559 100644 --- a/modules/purchase/purchase.py +++ b/modules/purchase/purchase.py @@ -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' diff --git a/modules/purchase/stock.py b/modules/purchase/stock.py index e99efe37a3..86cafce348 100644 --- a/modules/purchase/stock.py +++ b/modules/purchase/stock.py @@ -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 diff --git a/modules/purchase_amendment/purchase.py b/modules/purchase_amendment/purchase.py index 431790f566..1ead471d97 100644 --- a/modules/purchase_amendment/purchase.py +++ b/modules/purchase_amendment/purchase.py @@ -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 diff --git a/modules/purchase_blanket_agreement/purchase.py b/modules/purchase_blanket_agreement/purchase.py index 767fe80b74..4d7680a898 100644 --- a/modules/purchase_blanket_agreement/purchase.py +++ b/modules/purchase_blanket_agreement/purchase.py @@ -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() diff --git a/modules/purchase_request/purchase_request.py b/modules/purchase_request/purchase_request.py index 6826ebde03..6372fc4247 100644 --- a/modules/purchase_request/purchase_request.py +++ b/modules/purchase_request/purchase_request.py @@ -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): diff --git a/modules/purchase_request_quotation/purchase.py b/modules/purchase_request_quotation/purchase.py index b3c8fcde97..2923966586 100644 --- a/modules/purchase_request_quotation/purchase.py +++ b/modules/purchase_request_quotation/purchase.py @@ -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): diff --git a/modules/purchase_requisition/purchase.py b/modules/purchase_requisition/purchase.py index 0e4c2996c5..2dc23d153b 100644 --- a/modules/purchase_requisition/purchase.py +++ b/modules/purchase_requisition/purchase.py @@ -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): diff --git a/modules/purchase_secondary_unit/product.py b/modules/purchase_secondary_unit/product.py index beb29dc91e..9cb9788255 100644 --- a/modules/purchase_secondary_unit/product.py +++ b/modules/purchase_secondary_unit/product.py @@ -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): diff --git a/modules/purchase_secondary_unit/purchase.py b/modules/purchase_secondary_unit/purchase.py index ac98a5e9f0..9410b06bfa 100644 --- a/modules/purchase_secondary_unit/purchase.py +++ b/modules/purchase_secondary_unit/purchase.py @@ -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) diff --git a/modules/sale/invoice.py b/modules/sale/invoice.py index 80be2cb39b..5e45bcbdb6 100644 --- a/modules/sale/invoice.py +++ b/modules/sale/invoice.py @@ -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): diff --git a/modules/sale/sale.py b/modules/sale/sale.py index 4c09c81f4d..491c0bf7e1 100644 --- a/modules/sale/sale.py +++ b/modules/sale/sale.py @@ -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): diff --git a/modules/sale/stock.py b/modules/sale/stock.py index 5b4c5ff4fe..366dca5f75 100644 --- a/modules/sale/stock.py +++ b/modules/sale/stock.py @@ -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): diff --git a/modules/sale_advance_payment/sale.py b/modules/sale_advance_payment/sale.py index 9904eea4fe..6140a59abb 100644 --- a/modules/sale_advance_payment/sale.py +++ b/modules/sale_advance_payment/sale.py @@ -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): diff --git a/modules/sale_amendment/sale.py b/modules/sale_amendment/sale.py index 6e05b20648..2f3ccc790d 100644 --- a/modules/sale_amendment/sale.py +++ b/modules/sale_amendment/sale.py @@ -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 diff --git a/modules/sale_blanket_agreement/sale.py b/modules/sale_blanket_agreement/sale.py index 1d2f536ad8..73f5a3de7e 100644 --- a/modules/sale_blanket_agreement/sale.py +++ b/modules/sale_blanket_agreement/sale.py @@ -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() diff --git a/modules/sale_complaint/complaint.py b/modules/sale_complaint/complaint.py index 1220f9cf3f..ad40491f7d 100644 --- a/modules/sale_complaint/complaint.py +++ b/modules/sale_complaint/complaint.py @@ -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): diff --git a/modules/sale_extra/sale.py b/modules/sale_extra/sale.py index 6c2285e269..0263ae17ad 100644 --- a/modules/sale_extra/sale.py +++ b/modules/sale_extra/sale.py @@ -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() diff --git a/modules/sale_gift_card/sale.py b/modules/sale_gift_card/sale.py index 56c2627b8a..951fd256e0 100644 --- a/modules/sale_gift_card/sale.py +++ b/modules/sale_gift_card/sale.py @@ -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 diff --git a/modules/sale_point/sale.py b/modules/sale_point/sale.py index 869af52e89..e8fd57e840 100644 --- a/modules/sale_point/sale.py +++ b/modules/sale_point/sale.py @@ -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): diff --git a/modules/sale_product_recommendation/sale.py b/modules/sale_product_recommendation/sale.py index 179f729e60..500c806498 100644 --- a/modules/sale_product_recommendation/sale.py +++ b/modules/sale_product_recommendation/sale.py @@ -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): diff --git a/modules/sale_promotion_coupon/sale.py b/modules/sale_promotion_coupon/sale.py index fa88b57528..cebcceb171 100644 --- a/modules/sale_promotion_coupon/sale.py +++ b/modules/sale_promotion_coupon/sale.py @@ -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): diff --git a/modules/sale_secondary_unit/product.py b/modules/sale_secondary_unit/product.py index 292d651609..1b98dd068d 100644 --- a/modules/sale_secondary_unit/product.py +++ b/modules/sale_secondary_unit/product.py @@ -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): diff --git a/modules/sale_secondary_unit/sale.py b/modules/sale_secondary_unit/sale.py index 92e12fa89e..758e637bd7 100644 --- a/modules/sale_secondary_unit/sale.py +++ b/modules/sale_secondary_unit/sale.py @@ -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) diff --git a/modules/sale_shipment_cost/sale.py b/modules/sale_shipment_cost/sale.py index 5230f493db..29e6d9e919 100644 --- a/modules/sale_shipment_cost/sale.py +++ b/modules/sale_shipment_cost/sale.py @@ -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): diff --git a/modules/sale_shipment_cost/stock.py b/modules/sale_shipment_cost/stock.py index 06209e7dc7..f2f85467a2 100644 --- a/modules/sale_shipment_cost/stock.py +++ b/modules/sale_shipment_cost/stock.py @@ -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): diff --git a/modules/sale_subscription/subscription.py b/modules/sale_subscription/subscription.py index 4a5f35205b..51919f4ca8 100644 --- a/modules/sale_subscription/subscription.py +++ b/modules/sale_subscription/subscription.py @@ -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): diff --git a/modules/stock/inventory.py b/modules/stock/inventory.py index b76ffde8ee..869cd09a07 100644 --- a/modules/stock/inventory.py +++ b/modules/stock/inventory.py @@ -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): diff --git a/modules/stock/move.py b/modules/stock/move.py index 81facaafa8..b32ba5e314 100644 --- a/modules/stock/move.py +++ b/modules/stock/move.py @@ -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): diff --git a/modules/stock/shipment.py b/modules/stock/shipment.py index 44e7ca2da0..26d47feb36 100644 --- a/modules/stock/shipment.py +++ b/modules/stock/shipment.py @@ -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', diff --git a/modules/stock_assign_manual/stock.py b/modules/stock_assign_manual/stock.py index 0ee8cd1a4b..393a406cf1 100644 --- a/modules/stock_assign_manual/stock.py +++ b/modules/stock_assign_manual/stock.py @@ -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): diff --git a/modules/stock_forecast/forecast.py b/modules/stock_forecast/forecast.py index d2f0f34add..ab54f0f4c5 100644 --- a/modules/stock_forecast/forecast.py +++ b/modules/stock_forecast/forecast.py @@ -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): diff --git a/modules/stock_lot/stock.py b/modules/stock_lot/stock.py index bece966f44..98effc11f8 100644 --- a/modules/stock_lot/stock.py +++ b/modules/stock_lot/stock.py @@ -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 diff --git a/modules/stock_lot_unit/stock.py b/modules/stock_lot_unit/stock.py index 939244a9ff..32e35ef965 100644 --- a/modules/stock_lot_unit/stock.py +++ b/modules/stock_lot_unit/stock.py @@ -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): diff --git a/modules/stock_quantity_early_planning/stock.py b/modules/stock_quantity_early_planning/stock.py index 0519c0b9f4..74f564c7f1 100644 --- a/modules/stock_quantity_early_planning/stock.py +++ b/modules/stock_quantity_early_planning/stock.py @@ -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() diff --git a/modules/stock_quantity_issue/stock.py b/modules/stock_quantity_issue/stock.py index 889d530e10..4c5fdb7cc2 100644 --- a/modules/stock_quantity_issue/stock.py +++ b/modules/stock_quantity_issue/stock.py @@ -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): diff --git a/modules/stock_shipment_cost/stock.py b/modules/stock_shipment_cost/stock.py index 4dba4bb97f..a53b991809 100644 --- a/modules/stock_shipment_cost/stock.py +++ b/modules/stock_shipment_cost/stock.py @@ -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',