[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
This commit is contained in:
Victor Feyens
2021-11-26 09:44:57 +00:00
parent 162fadd48e
commit 659bc441da
+6 -3
View File
@@ -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)