[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.
This commit is contained in:
Cedric Snauwaert
2017-03-10 14:45:22 +01:00
parent 82a663db25
commit c781c1e5e2
+11
View File
@@ -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)