[IMP] base: avoid setup_models() when creating custom selection
There exists an optimization when creating fields to avoid calling `setup_models()` for fields when creating a custom model, since the latter already calls `setup_models()`. We add the same optimization for field selections, so that creating a custom field with selections only calls `setup_models()` once. Note that both optimizations are combined when creating custom models with selection fields: `setup_models()` will be called once for all. closes odoo/odoo#78514 Related: odoo/enterprise#21746 Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
This commit is contained in:
@@ -1319,16 +1319,22 @@ class IrModelSelection(models.Model):
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
field_ids = {vals['field_id'] for vals in vals_list}
|
||||
field_names = set()
|
||||
for field in self.env['ir.model.fields'].browse(field_ids):
|
||||
field_names.add((field.model, field.name))
|
||||
if field.state != 'manual':
|
||||
raise UserError(_('Properties of base fields cannot be altered in this manner! '
|
||||
'Please modify them through Python code, '
|
||||
'preferably through a custom addon!'))
|
||||
recs = super().create(vals_list)
|
||||
|
||||
# setup models; this re-initializes model in registry
|
||||
self.flush()
|
||||
self.pool.setup_models(self._cr)
|
||||
if any(
|
||||
model in self.pool and name in self.pool[model]._fields
|
||||
for model, name in field_names
|
||||
):
|
||||
# setup models; this re-initializes model in registry
|
||||
self.flush()
|
||||
self.pool.setup_models(self._cr)
|
||||
|
||||
return recs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user