[FIX] base: create parent XML ids before XML id
When a module creates a record from a model M that `_inherits` from some parent model P, the method `_load_records` creates an XML id for the record, and an extra XML id for the parent record. The corresponding `ir.model.data` entries must be created in the right order (parent record, then record), so that the record is deleted before its parent record. closes odoo/odoo#28805
This commit is contained in:
@@ -1471,17 +1471,20 @@ class IrModelData(models.Model):
|
||||
|
||||
# rows to insert
|
||||
rowf = "(%s, %s, %s, %s, %s, now() at time zone 'UTC', now() at time zone 'UTC')"
|
||||
rows = set()
|
||||
rows = tools.OrderedSet()
|
||||
for data in data_list:
|
||||
prefix, suffix = data['xml_id'].split('.', 1)
|
||||
record = data['record']
|
||||
noupdate = bool(data.get('noupdate'))
|
||||
rows.add((prefix, suffix, record._name, record.id, noupdate))
|
||||
# also create XML ids for parent records
|
||||
# First create XML ids for parent records, then create XML id for
|
||||
# record. The order reflects their actual creation order. This order
|
||||
# is relevant for the uninstallation process: the record must be
|
||||
# deleted before its parent records.
|
||||
for parent_model, parent_field in record._inherits.items():
|
||||
parent = record[parent_field]
|
||||
puffix = suffix + '_' + parent_model.replace('.', '_')
|
||||
rows.add((prefix, puffix, parent._name, parent.id, noupdate))
|
||||
rows.add((prefix, suffix, record._name, record.id, noupdate))
|
||||
|
||||
for sub_rows in self.env.cr.split_for_in_conditions(rows):
|
||||
# insert rows or update them
|
||||
|
||||
Reference in New Issue
Block a user