Skip to content

Commit

Permalink
[IMP] account: onchange at create
Browse files Browse the repository at this point in the history
Make the onchange calls at invoice creation deterministic and
extendable.

opw-1951314
  • Loading branch information
nim-odoo committed Mar 25, 2019
1 parent a4f9b48 commit 1e9336a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions addons/account/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from collections import OrderedDict
import json
import re
import uuid
Expand Down Expand Up @@ -517,10 +518,7 @@ def create(self, vals):
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)
Expand Down Expand Up @@ -1591,6 +1589,13 @@ def preview_invoice(self):
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"
Expand Down

0 comments on commit 1e9336a

Please sign in to comment.