diff --git a/modules/account_invoice/invoice.py b/modules/account_invoice/invoice.py index 619bc94312..cde85a53c8 100644 --- a/modules/account_invoice/invoice.py +++ b/modules/account_invoice/invoice.py @@ -437,6 +437,7 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin): @fields.depends(methods=['set_journal', 'on_change_party']) def on_change_type(self): + self.set_journal() self.on_change_party() @classmethod @@ -446,18 +447,16 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin): else: return ['expense'] - @fields.depends('state', 'journal', 'type') - def on_change_with_journal(self, pattern=None): + @fields.depends('type') + def set_journal(self, pattern=None): pool = Pool() Journal = pool.get('account.journal') - if self.state != 'draft': - return self.journal pattern = pattern.copy() if pattern is not None else {} pattern.setdefault('type', { 'out': 'revenue', 'in': 'expense', }.get(self.type)) - return Journal.find(pattern) + self.journal = Journal.find(pattern) @classmethod def order_accounting_date(cls, tables): diff --git a/modules/account_invoice_defer/account.py b/modules/account_invoice_defer/account.py index cdd5d46537..f4284c0254 100644 --- a/modules/account_invoice_defer/account.py +++ b/modules/account_invoice_defer/account.py @@ -164,8 +164,12 @@ class InvoiceDeferred(Workflow, ModelSQL, ModelView): else: return ['expense'] + @fields.depends(methods=['set_journal']) + def on_change_type(self): + self.set_journal() + @fields.depends('type') - def on_change_with_journal(self, pattern=None): + def set_journal(self, pattern=None): pool = Pool() Journal = pool.get('account.journal') pattern = pattern.copy() if pattern is not None else {} @@ -173,7 +177,7 @@ class InvoiceDeferred(Workflow, ModelSQL, ModelView): 'out': 'revenue', 'in': 'expense', }.get(self.type)) - return Journal.find(pattern) + self.journal = Journal.find(pattern) @fields.depends('invoice_line', 'start_date', 'company') def on_change_invoice_line(self): diff --git a/modules/purchase/purchase.py b/modules/purchase/purchase.py index ab26194686..b78b8b5c04 100644 --- a/modules/purchase/purchase.py +++ b/modules/purchase/purchase.py @@ -758,7 +758,7 @@ class Purchase( account=party.account_payable_used, payment_term=self.payment_term, ) - invoice.journal = invoice.on_change_with_journal() + invoice.set_journal() return invoice def create_invoice(self): diff --git a/modules/sale/sale.py b/modules/sale/sale.py index de9c5a18e8..d730fff7e9 100644 --- a/modules/sale/sale.py +++ b/modules/sale/sale.py @@ -846,7 +846,7 @@ class Sale( currency=self.currency, account=party.account_receivable_used, ) - invoice.journal = invoice.on_change_with_journal() + invoice.set_journal() invoice.payment_term = self.payment_term return invoice diff --git a/modules/sale_subscription/subscription.py b/modules/sale_subscription/subscription.py index ea81b900e3..7bcf4c0439 100644 --- a/modules/sale_subscription/subscription.py +++ b/modules/sale_subscription/subscription.py @@ -489,7 +489,7 @@ class Subscription(Workflow, ModelSQL, ModelView): account=party.account_receivable_used, ) invoice.invoice_date = self.next_invoice_date - invoice.journal = invoice.on_change_with_journal() + invoice.set_journal() invoice.payment_term = self.payment_term return invoice