Skip to content

Commit 670685e

Browse files
committed
[IMP] util/fields: use the new report util
Use the new utility function designed specifically for adding a report with a list of records.
1 parent a377953 commit 670685e

1 file changed

Lines changed: 38 additions & 27 deletions

File tree

src/util/fields.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def make_index_name(table_name, column_name):
7272
target_of,
7373
)
7474
from .records import _remove_import_export_paths
75-
from .report import add_to_migration_reports, get_anchor_link_to_record
75+
from .report import add_to_migration_reports, report_with_list
7676

7777
# python3 shims
7878
try:
@@ -1470,11 +1470,26 @@ def _update_field_usage_multi(cr, models, old, new, domain_adapter=None, skip_in
14701470
)
14711471
""".format(col_prefix=col_prefix, name=get_value_or_en_translation(cr, "ir_act_server", "name"))
14721472
cr.execute(q, {"old_pattern": p["old_pattern"], "old": p["old"], "standard_modules": tuple(standard_modules)})
1473-
li = ""
1474-
if cr.rowcount:
1475-
li = "".join(
1476-
"<li>{}</li>".format(get_anchor_link_to_record("ir.actions.server", aid, aname))
1477-
for aid, aname in cr.fetchall()
1473+
1474+
model_text = "All models"
1475+
if only_models:
1476+
model_text = "Models " + ", ".join("<kbd>{}</kbd>".format(m) for m in only_models)
1477+
total = cr.rowcount
1478+
if total:
1479+
summary = (
1480+
"{model_text}: the field <kbd>{old}</kbd> has been renamed to <kbd>{new}</kbd>. "
1481+
"The following server actions may need an update. "
1482+
"If a server action is a standard one and you haven't made any modifications, you may ignore it."
1483+
).format(model_text=model_text, old=old, new=new)
1484+
report_with_list(
1485+
summary=summary,
1486+
data=cr.fetchall(),
1487+
columns=("id", "name"),
1488+
row_format="{action_link}",
1489+
links={"action_link": ("ir.actions.server", "id", "name")},
1490+
total=total,
1491+
limit=20,
1492+
category="Fields renamed",
14781493
)
14791494

14801495
if column_exists(cr, "ir_model_fields", "compute"):
@@ -1493,28 +1508,24 @@ def _update_field_usage_multi(cr, models, old, new, domain_adapter=None, skip_in
14931508
)
14941509
"""
14951510
cr.execute(q, {"old_pattern": p["old_pattern"], "standard_modules": tuple(standard_modules)})
1496-
if cr.rowcount:
1497-
li += "".join(
1498-
"<li>{}</li>".format(get_anchor_link_to_record("ir.model.fields", fid, fname))
1499-
for fid, fname in cr.fetchall()
1511+
1512+
total = cr.rowcount
1513+
if total:
1514+
summary = (
1515+
"{model_text}: the field <kbd>{old}</kbd> has been renamed to <kbd>{new}</kbd>. "
1516+
"The following compute methods of other fields may need an update. "
1517+
"If a field is a standard one and you haven't made any modifications, you may ignore it."
1518+
).format(model_text=model_text, old=old, new=new)
1519+
report_with_list(
1520+
summary=summary,
1521+
data=cr.fetchall(),
1522+
columns=("id", "name"),
1523+
row_format="{field_link}",
1524+
links={"field_link": ("ir.model.fields", "id", "name")},
1525+
total=total,
1526+
limit=20,
1527+
category="Fields renamed",
15001528
)
1501-
if li:
1502-
model_text = "All models"
1503-
if only_models:
1504-
model_text = "Models " + ", ".join("<kbd>{}</kbd>".format(m) for m in only_models)
1505-
add_to_migration_reports(
1506-
"""
1507-
<details>
1508-
<summary>
1509-
{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.
1510-
If a server action or a field is a standard one and you haven't made any modifications, you may ignore them.
1511-
</summary>
1512-
<ul>{li}</ul>
1513-
</details>
1514-
""".format(**locals()),
1515-
category="Fields renamed",
1516-
format="html",
1517-
)
15181529

15191530
# if we stay on the same model. (no usage of dotted-path) (only works for domains and related)
15201531
if "." not in old and "." not in new:

0 commit comments

Comments
 (0)