Skip to content

Commit 0833a35

Browse files
bda-odooKangOl
authored andcommitted
[FIX] util/fields: improve report to be more precise
When renaming a field, we've been matching the impacted server actions too broadly. We now ignore standard server actions that we know are correct (via their noupdate flag). opw-4126696 closes #139 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 40500e6 commit 0833a35

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/util/fields.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
from psycopg2 import sql
1919
from psycopg2.extras import Json
2020

21+
try:
22+
from odoo import modules
23+
except ImportError:
24+
from openerp import modules
25+
2126
try:
2227
from odoo import release
2328
from odoo.osv import expression
@@ -1149,17 +1154,23 @@ def _update_field_usage_multi(cr, models, old, new, domain_adapter=None, skip_in
11491154
col_prefix = ""
11501155
if not column_exists(cr, "ir_act_server", "condition"):
11511156
col_prefix = "--" # sql comment the line
1152-
1157+
standard_modules = set(modules.get_modules()) | {"__upgrade__"}
11531158
q = """
1154-
SELECT id, {name}
1155-
FROM ir_act_server
1156-
WHERE state = 'code'
1157-
AND (code ~ %(old_pattern)s
1158-
{col_prefix} OR condition ~ %(old)s
1159+
SELECT a.id, a.{name}
1160+
FROM ir_act_server a
1161+
LEFT JOIN ir_model_data d
1162+
ON d.res_id = a.id
1163+
AND d.model = 'ir.actions.server'
1164+
WHERE a.state = 'code'
1165+
AND (a.code ~ %(old_pattern)s
1166+
{col_prefix} OR a.condition ~ %(old)s
11591167
)
1160-
"""
1161-
1162-
cr.execute(q.format(col_prefix=col_prefix, name=get_value_or_en_translation(cr, "ir_act_server", "name")), p)
1168+
AND ( d.module IS NULL -- custom action
1169+
OR d.module NOT IN %(standard_modules)s
1170+
OR (d.module IN %(standard_modules)s AND d.noupdate)
1171+
)
1172+
""".format(col_prefix=col_prefix, name=get_value_or_en_translation(cr, "ir_act_server", "name"))
1173+
cr.execute(q, {"old_pattern": p["old_pattern"], "old": p["old"], "standard_modules": tuple(standard_modules)})
11631174
if cr.rowcount:
11641175
li = "".join(
11651176
"<li>{}</li>".format(get_anchor_link_to_record("ir.actions.server", aid, aname))
@@ -1173,6 +1184,7 @@ def _update_field_usage_multi(cr, models, old, new, domain_adapter=None, skip_in
11731184
<details>
11741185
<summary>
11751186
{model_text}: the field <kbd>{old}</kbd> has been renamed to <kbd>{new}</kbd>. The following server actions may need update.
1187+
If the server action is a standard one and you haven't made any modifications, you may ignore them.
11761188
</summary>
11771189
<ul>{li}</ul>
11781190
</details>

0 commit comments

Comments
 (0)