Skip to content

Commit 5a5acb2

Browse files
committed
[FIX] util.merge_model
Don't change the `res_model_id` of bound indirect references. Their `res_id` won't point to the correct record (if it even exists). Those are records that haven't been remapped before the merge. They will be removed along the target model removal. closes #236 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 36c0e5e commit 5a5acb2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/util/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,10 @@ def merge_model(cr, source, target, drop_table=True, fields_mapping=None, ignore
421421
cr.execute("SELECT model, id FROM ir_model WHERE model in %s", ((source, target),))
422422
model_ids = dict(cr.fetchall())
423423
mapping = {model_ids[source]: model_ids[target]}
424-
ignores = ["ir_model", "ir_model_fields", "ir_model_constraint", "ir_model_relation"]
424+
425+
ir_model_tables = ["ir_model", "ir_model_fields", "ir_model_constraint", "ir_model_relation"]
426+
ignores = ir_model_tables + [ir.table for ir in indirect_references(cr, bound_only=True) if ir.res_model_id]
427+
425428
replace_record_references_batch(cr, mapping, "ir.model", replace_xmlid=False, ignores=ignores)
426429

427430
# remap the fields on ir_model_fields
@@ -488,7 +491,7 @@ def merge_model(cr, source, target, drop_table=True, fields_mapping=None, ignore
488491
)
489492

490493
for ir in indirect_references(cr):
491-
if ir.res_model and not ir.res_id and ir.table not in ignores:
494+
if ir.res_model and not ir.res_id and ir.table not in ir_model_tables:
492495
# only update unbound references, other ones have been updated by the call to
493496
# `replace_record_references_batch`
494497
where_clauses = []

0 commit comments

Comments
 (0)