From 5eb40654865d3e04526d98de2a10c0c02dde0c0c Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 25 Mar 2019 13:11:57 +0000 Subject: [PATCH] [IMP] account: onchange at create Make the onchange calls at invoice creation deterministic and extendable. opw-1951314 --- addons/account/models/account_invoice.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 90b1727531d..adbd2102979 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -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"