diff options
| author | Victor Feyens <vfe@odoo.com> | 2020-07-14 14:29:10 +0000 |
|---|---|---|
| committer | Victor Feyens <vfe@odoo.com> | 2020-07-23 16:38:17 +0000 |
| commit | 71ab12840bc787ca486202255cd6faa21281b9e1 (patch) | |
| tree | dc8b093e25f9215f2f2c53ff0a084500c88ef560 /addons/account/models | |
| parent | c69a092b98ad7a7f8e03024d170efa30038c89a0 (diff) | |
[IMP] *: do not specify unwanted defaults in default_get
When default_get is called, the wanted fields are specified through the
fields_list arg. It is useless to fill the values for unwanted fields.
As default_get is called for nearly all records creation, simplifying
the default_get overrides:
* remove potential wrong side-effects of the values
* remove some useless or wrong defaults computations (searches, refs,
...)
Diffstat (limited to 'addons/account/models')
| -rw-r--r-- | addons/account/models/account_account.py | 2 | ||||
| -rw-r--r-- | addons/account/models/account_tax.py | 8 |
2 files changed, 6 insertions, 4 deletions
diff --git a/addons/account/models/account_account.py b/addons/account/models/account_account.py index 1622338baf2..b7da1a1ac37 100644 --- a/addons/account/models/account_account.py +++ b/addons/account/models/account_account.py @@ -305,6 +305,8 @@ class AccountAccount(models.Model): """If we're creating a new account through a many2one, there are chances that we typed the account code instead of its name. In that case, switch both fields values. """ + if 'name' not in default_fields and 'code' not in default_fields: + return super().default_get(default_fields) default_name = self._context.get('default_name') default_code = self._context.get('default_code') if default_name and not default_code: diff --git a/addons/account/models/account_tax.py b/addons/account/models/account_tax.py index e9b69319652..19977d46831 100644 --- a/addons/account/models/account_tax.py +++ b/addons/account/models/account_tax.py @@ -98,21 +98,21 @@ class AccountTax(models.Model): ] @api.model - def default_get(self, vals): + def default_get(self, fields_list): # company_id is added so that we are sure to fetch a default value from it to use in repartition lines, below - rslt = super(AccountTax, self).default_get(vals + ['company_id']) + rslt = super(AccountTax, self).default_get(fields_list + ['company_id']) company_id = rslt.get('company_id') company = self.env['res.company'].browse(company_id) - if 'refund_repartition_line_ids' in vals: + if 'refund_repartition_line_ids' in fields_list: # We write on the related country_id field so that the field is recomputed. Without that, it will stay empty until we save the record. rslt['refund_repartition_line_ids'] = [ (0, 0, {'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), (0, 0, {'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), ] - if 'invoice_repartition_line_ids' in vals: + if 'invoice_repartition_line_ids' in fields_list: # We write on the related country_id field so that the field is recomputed. Without that, it will stay empty until we save the record. rslt['invoice_repartition_line_ids'] = [ (0, 0, {'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), |
