Skip to content

Commit bb9a205

Browse files
committed
[IMP] util/fields: report computes that may need adaptation
When fields are renamed, computes referencing them will require an update. We don't do that automatically because of risks. Instead, we report computed fields that may need an update. closes #202 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 946deba commit bb9a205

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/util/fields.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,20 +1191,44 @@ def _update_field_usage_multi(cr, models, old, new, domain_adapter=None, skip_in
11911191
)
11921192
""".format(col_prefix=col_prefix, name=get_value_or_en_translation(cr, "ir_act_server", "name"))
11931193
cr.execute(q, {"old_pattern": p["old_pattern"], "old": p["old"], "standard_modules": tuple(standard_modules)})
1194+
li = ""
11941195
if cr.rowcount:
11951196
li = "".join(
11961197
"<li>{}</li>".format(get_anchor_link_to_record("ir.actions.server", aid, aname))
11971198
for aid, aname in cr.fetchall()
11981199
)
1200+
1201+
if column_exists(cr, "ir_model_fields", "compute"):
1202+
# Modifying compute methods is similarly as dangerous.
1203+
# Only report potential compute methods that may need an update.
1204+
q = """
1205+
SELECT f.id, f.name
1206+
FROM ir_model_fields f
1207+
LEFT JOIN ir_model_data d
1208+
ON d.res_id = f.id
1209+
AND d.model = 'ir.model.fields'
1210+
WHERE f.compute ~ %(old_pattern)s
1211+
AND ( d.module IS NULL -- custom action
1212+
OR d.module NOT IN %(standard_modules)s
1213+
OR (d.module IN %(standard_modules)s AND d.noupdate)
1214+
)
1215+
"""
1216+
cr.execute(q, {"old_pattern": p["old_pattern"], "standard_modules": tuple(standard_modules)})
1217+
if cr.rowcount:
1218+
li += "".join(
1219+
"<li>{}</li>".format(get_anchor_link_to_record("ir.model.fields", fid, fname))
1220+
for fid, fname in cr.fetchall()
1221+
)
1222+
if li:
11991223
model_text = "All models"
12001224
if only_models:
12011225
model_text = "Models " + ", ".join("<kbd>{}</kbd>".format(m) for m in only_models)
12021226
add_to_migration_reports(
12031227
"""
12041228
<details>
12051229
<summary>
1206-
{model_text}: the field <kbd>{old}</kbd> has been renamed to <kbd>{new}</kbd>. The following server actions may need update.
1207-
If the server action is a standard one and you haven't made any modifications, you may ignore them.
1230+
{model_text}: the field <kbd>{old}</kbd> has been renamed to <kbd>{new}</kbd>. The following server actions and compute methods of other fields may need an update:
1231+
If a server action or a field is a standard one and you haven't made any modifications, you may ignore them.
12081232
</summary>
12091233
<ul>{li}</ul>
12101234
</details>

0 commit comments

Comments
 (0)