Skip to content

Commit 9b1dbb4

Browse files
committed
[IMP] util.rename_xmlid : Adapt t-call, t-value and t-name References
When renaming a view, we should also update its references in other views where it is used in t-call, t-value and t-name attributes. This ensures consistency and prevents broken references in dependent views.
1 parent 23df9e5 commit 9b1dbb4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/util/records.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,34 @@ def rename_xmlid(cr, old, new, noupdate=None, on_collision="fail"):
796796
# Don't change the view keys inconditionally to avoid changing unrelated views.
797797
cr.execute("UPDATE ir_ui_view SET key = %s WHERE key = %s", [new, old])
798798

799+
# Adapting t-call, t-value and t-name references in views
800+
search_pattern = r"""\yt-(call|name|value)=(["']){}\2""".format(old)
801+
replace_pattern = r"t-\1=\2{}\2".format(new)
802+
if version_gte("16.0"):
803+
arch_col = get_value_or_en_translation(cr, "ir_ui_view", "arch_db")
804+
replace_in_all_jsonb_values(
805+
cr,
806+
"ir_ui_view",
807+
"arch_db",
808+
PGRegexp(search_pattern),
809+
replace_pattern,
810+
extra_filter=cr.mogrify("{} ~ %s".format(arch_col), [search_pattern]).decode(),
811+
)
812+
else:
813+
arch_col = "arch_db" if column_exists(cr, "ir_ui_view", "arch_db") else "arch"
814+
cr.execute(
815+
format_query(
816+
cr,
817+
"""
818+
UPDATE ir_ui_view
819+
SET {arch} = regexp_replace({arch}, %s, %s, 'g')
820+
WHERE {arch} ~ %s
821+
""",
822+
arch=arch_col,
823+
),
824+
[search_pattern, replace_pattern, search_pattern],
825+
)
826+
799827
if model == "ir.ui.menu" and column_exists(cr, "res_users_settings", "homemenu_config"):
800828
query = """
801829
UPDATE res_users_settings

0 commit comments

Comments
 (0)