summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2018-11-19 14:20:01 +0000
committerRaphael Collet <rco@odoo.com>2018-11-19 14:57:52 +0000
commit5eb2fbdec3e58c6b545cd7e96dc9a24adcd12b84 (patch)
treed548c8f508403996400bdf682a60c67965ab27f0
parent2e8cc564329dd455c15ffd69e6d8771815057344 (diff)
[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
-rw-r--r--odoo/addons/base/models/ir_model.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py
index 76524a10814..38e50600d22 100644
--- a/odoo/addons/base/models/ir_model.py
+++ b/odoo/addons/base/models/ir_model.py
@@ -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