From 659bc441da88a4efd4cc03d7fafac82c1391e88d Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Tue, 24 Nov 2020 13:20:28 +0000 Subject: [PATCH] [IMP] base: do not compute unwanted defaults for settings wizard. At create, the ORM fills the missing create values with the defaults, calling default_get. In the case of res.config.settings model, the default_get overrides triggers a lot of operations to manage its custom field logic (config parameters, defaults, modules installation, ...). This slows down the creation (and application) of settings updates for "nothing". This commit ensures the defaults are not recomputed for fields whose value was provided to the create call, reducing the effective time of settings flow. Part-of: odoo/odoo#62249 --- odoo/addons/base/models/res_config.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/odoo/addons/base/models/res_config.py b/odoo/addons/base/models/res_config.py index 3642bc11280..7576568ddd6 100644 --- a/odoo/addons/base/models/res_config.py +++ b/odoo/addons/base/models/res_config.py @@ -441,7 +441,7 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin) self._onchange_methods[name].append(method) @api.model - def _get_classified_fields(self): + def _get_classified_fields(self, fnames=None): """ return a dictionary with the fields classified by category:: { 'default': [('default_foo', 'model', 'foo'), ...], @@ -454,9 +454,12 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin) IrModule = self.env['ir.module.module'] Groups = self.env['res.groups'] ref = self.env.ref + if fnames is None: + fnames = self._fields.keys() defaults, groups, modules, configs, others = [], [], [], [], [] - for name, field in self._fields.items(): + for name in fnames: + field = self._fields[name] if name.startswith('default_'): if not hasattr(field, 'default_model'): raise Exception("Field %s without attribute 'default_model'" % field) @@ -493,7 +496,7 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin) def default_get(self, fields): IrDefault = self.env['ir.default'] IrConfigParameter = self.env['ir.config_parameter'].sudo() - classified = self._get_classified_fields() + classified = self._get_classified_fields(fields) res = super(ResConfigSettings, self).default_get(fields)