Skip to content

Commit 2c10634

Browse files
committed
[FIX] util/fields : rename relation field
This commit aims to rename custom relation field which are being renamed during upgrade. Issue: X is standard M2O field Y is a custom O2M field to X When the X is renamed to Z during upgrade we will have to update Y field's relation_field data accordingly to avoid field error. closes #12 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent e94ed12 commit 2c10634

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/util/fields.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,17 @@ def rename_field(cr, model, old, new, update_references=True, domain_adapter=Non
409409
name = "%s_%s" % (name, fid)
410410
cr.execute("UPDATE ir_model_data SET name=%s WHERE model='ir.model.fields' AND res_id=%s", [name, fid])
411411
cr.execute("UPDATE ir_property SET name=%s WHERE fields_id=%s", [new, fid])
412+
# Updates custom field relation name to match the renamed standard field during upgrade.
413+
cr.execute(
414+
"""
415+
UPDATE ir_model_fields
416+
SET relation_field = %s
417+
WHERE relation = %s
418+
AND relation_field = %s
419+
AND state = 'manual'
420+
""",
421+
[new, model, old],
422+
)
412423

413424
if table_exists(cr, "ir_translation"):
414425
cr.execute(

0 commit comments

Comments
 (0)