diff --git a/odoo/addons/base/models/ir_fields.py b/odoo/addons/base/models/ir_fields.py index 619d66ab4e1..0ed56061caa 100644 --- a/odoo/addons/base/models/ir_fields.py +++ b/odoo/addons/base/models/ir_fields.py @@ -640,37 +640,3 @@ class IrFieldsConverter(models.AbstractModel): commands.append(Command.create(writable)) return commands, warnings - -class O2MIdMapper(models.AbstractModel): - """ - Updates the base class to support setting xids directly in create by - providing an "id" key (otherwise stripped by create) during an import - (which should strip 'id' from the input data anyway) - """ - _inherit = 'base' - - # sadly _load_records_create is only called for the toplevel record so we - # can't hook into that - @api.model_create_multi - @api.returns('self', lambda value: value.id) - def create(self, vals_list): - recs = super().create(vals_list) - - import_module = self.env.context.get('_import_current_module') - if not import_module: # not an import -> bail - return recs - noupdate = self.env.context.get('noupdate', False) - - xids = (v.get('id') for v in vals_list) - self.env['ir.model.data']._update_xmlids([ - { - 'xml_id': xid if '.' in xid else ('%s.%s' % (import_module, xid)), - 'record': rec, - # note: this is not used when updating o2ms above... - 'noupdate': noupdate, - } - for rec, xid in zip(recs, xids) - if xid and isinstance(xid, str) - ]) - - return recs diff --git a/odoo/models.py b/odoo/models.py index 62f9a206d3e..006e72b89bb 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -3856,13 +3856,13 @@ class BaseModel(metaclass=MetaModel): self = self.browse() self.check_access_rights('create') - vals_list = self._prepare_create_values(vals_list) + new_vals_list = self._prepare_create_values(vals_list) # classify fields for each record data_list = [] determine_inverses = defaultdict(set) # {inverse: fields} - for vals in vals_list: + for vals in new_vals_list: precomputed = vals.pop('__precomputed__', ()) # distribute fields into sets for various purposes @@ -3957,6 +3957,28 @@ class BaseModel(metaclass=MetaModel): if self._check_company_auto: records._check_company() + + import_module = self.env.context.get('_import_current_module') + if not import_module: # not an import -> bail + return records + + # It is to support setting xids directly in create by + # providing an "id" key (otherwise stripped by create) during an import + # (which should strip 'id' from the input data anyway) + noupdate = self.env.context.get('noupdate', False) + + xids = (v.get('id') for v in vals_list) + self.env['ir.model.data']._update_xmlids([ + { + 'xml_id': xid if '.' in xid else ('%s.%s' % (import_module, xid)), + 'record': rec, + # note: this is not used when updating o2ms above... + 'noupdate': noupdate, + } + for rec, xid in zip(records, xids) + if xid and isinstance(xid, str) + ]) + return records def _prepare_create_values(self, vals_list):