From c781c1e5e2d186b1c03c5b60e522f8e730d59a0e Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Fri, 10 Mar 2017 14:08:06 +0100 Subject: [PATCH] [FIX] account: when changing settings, if currency has not change, don't update it this increases performance, reason is because when saving a res.config.setting, even if a field has not changed, they will be updated and this might trigger recomputation, and so on... Problem here is that when writing a currency_id to the company, all moves are impacted due to the company_currency_id which is a related stored field. And saving the settings in accounting can be pretty slow if we have lots of move. This fix reduce the time needed to save settings by not writing currency_id on the company if the value has not changed. --- addons/account/models/res_config.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/addons/account/models/res_config.py b/addons/account/models/res_config.py index f59285b7bd8..664fb58c505 100644 --- a/addons/account/models/res_config.py +++ b/addons/account/models/res_config.py @@ -108,3 +108,14 @@ class AccountConfigSettings(models.TransientModel): def onchange_account_yodlee(self): if self.module_account_yodlee: self.module_account_plaid = True + + @api.model + def create(self, values): + # Optimisation purpose, saving a res_config even without changing any values will trigger the write of all + # related values, including the currency_id field on res_company. This in turn will trigger the recomputation + # of account_move_line related field company_currency_id which can be slow depending on the number of entries + # in the database. Thus, if we do not explicitely change the currency_id, we should not write it on the company + if ('company_id' in values and 'currency_id' in values): + if self.env['res.company'].browse(values.get('company_id')).currency_id.id == values.get('currency_id'): + values.pop('currency_id') + return super(AccountConfigSettings, self).create(values) \ No newline at end of file