From 317ed37aee280a183ffcec23b8c93f64ca488508 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Wed, 5 Jul 2017 11:37:30 +0200 Subject: [PATCH] [FIX] account: Avoid to rewrite all the account codes on res_config creation opw-750892 Avoid to rewrite the `accounts_code_digits` on the company if the value is the same. As all the values are passed on the res.config creation, the related fields are rewriten on each res_config creation. Rewriting the `account_code_digits` on the company will trigger a write on all the account.account to complete the code the missing characters to complete the desired number of digit, leading to a sql_constraint. --- addons/account/models/res_config.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/addons/account/models/res_config.py b/addons/account/models/res_config.py index a6c806b20b0..4c16d8726c6 100644 --- a/addons/account/models/res_config.py +++ b/addons/account/models/res_config.py @@ -281,3 +281,17 @@ class AccountConfigSettings(models.TransientModel): 'res_id': self.env.user.company_id.id, 'target': 'current', } + + @api.model + def create(self, vals): + """ + Avoid to rewrite the `accounts_code_digits` on the company if the value is the same. As all the values are + passed on the res.config creation, the related fields are rewriten on each res_config creation. Rewriting + the `account_code_digits` on the company will trigger a write on all the account.account to complete the + code the missing characters to complete the desired number of digit, leading to a sql_constraint. + """ + if ('company_id' in vals and 'code_digits' in vals): + if self.env['res.company'].browse(vals.get('company_id')).accounts_code_digits == vals.get('code_digits'): + vals.pop('code_digits') + res = super(AccountConfigSettings, self).create(vals) + return res