[IMP] account: onchange at create

Make the onchange calls at invoice creation deterministic and
extendable.

opw-1951314
This commit is contained in:
Nicolas Martinelli
2019-03-25 13:16:14 +00:00
parent d8b45d24aa
commit 5eb4065486
+9 -4
View File
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from collections import OrderedDict
import json
import re
import uuid
@@ -517,10 +518,7 @@ class AccountInvoice(models.Model):
if not vals.get('journal_id') and vals.get('type'):
vals['journal_id'] = self.with_context(type=vals.get('type'))._default_journal().id
onchanges = {
'_onchange_partner_id': ['account_id', 'payment_term_id', 'fiscal_position_id', 'partner_bank_id'],
'_onchange_journal_id': ['currency_id'],
}
onchanges = self._get_onchange_create()
for onchange_method, changed_fields in onchanges.items():
if any(f not in vals for f in changed_fields):
invoice = self.new(vals)
@@ -1591,6 +1589,13 @@ class AccountInvoice(models.Model):
def _get_intrastat_country_id(self):
return self.partner_id.country_id.id
def _get_onchange_create(self):
return OrderedDict([
('_onchange_partner_id', ['account_id', 'payment_term_id', 'fiscal_position_id', 'partner_bank_id']),
('_onchange_journal_id', ['currency_id']),
])
class AccountInvoiceLine(models.Model):
_name = "account.invoice.line"
_description = "Invoice Line"