Set invoice journal only when type is changed
Using on_change_with does not work correctly for editable field because the value may be changed when the user does not expect it.
This commit is contained in:
1 parent
f2838915d4
commit
b0590200db
5 files changed
+13
-10
No files matched your search
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user