Skip to content

Commit

Permalink
[IMP] util.rename_xmlid : Adapt t-call, t-value and t-name References
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kmod-odoo committed Dec 2, 2024
1 parent 23df9e5 commit 4daaa9a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/util/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,30 @@ def rename_xmlid(cr, old, new, noupdate=None, on_collision="fail"):
# Don't change the view keys inconditionally to avoid changing unrelated views.
cr.execute("UPDATE ir_ui_view SET key = %s WHERE key = %s", [new, old])

# Updating t-call, t-value and t-name references in views
search_pattern = r"""\yt-(call|name|value)=(["']){}\2""".format(old)
replace_pattern = r"t-\1=\2{}\2".format(new)
if version_gte("16.0"):
arch_col = get_value_or_en_translation(cr, "ir_ui_view", "arch_db")
replace_in_all_jsonb_values(
cr,
"ir_ui_view",
"arch_db",
PGRegexp(search_pattern),
replace_pattern,
extra_filter=cr.mogrify("{} ~ %s".format(arch_col), [search_pattern]).decode(),
)
else:
arch_col = "arch_db" if column_exists(cr, "ir_ui_view", "arch_db") else "arch"
cr.execute(
"""
UPDATE ir_ui_view
SET {arch} = regexp_replace({arch}, %s, %s, 'g')
WHERE {arch} ~ %s
""".format(arch=arch_col),
[search_pattern, replace_pattern, search_pattern],
)

if model == "ir.ui.menu" and column_exists(cr, "res_users_settings", "homemenu_config"):
query = """
UPDATE res_users_settings
Expand Down

0 comments on commit 4daaa9a

Please sign in to comment.