Skip to content

Commit 77baefd

Browse files
committed
[FIX] util/fields: update depends on rename
Currently we are not updating the dependencies for custom compute fields which leads to test crawler failure when it tries to access the view and give: KeyError: 'old_field_name'
1 parent 5581c9f commit 77baefd

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/util/fields.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ def adapt_dict(d):
998998
# skip all inherit, they will be handled by the resursive call
999999
adapt_domains(cr, model, old, new, adapter=domain_adapter, skip_inherit="*", force_adapt=True)
10001000
adapt_related(cr, model, old, new, skip_inherit="*")
1001-
1001+
adapt_depends(cr, model, old, new)
10021002
inherited_models = tuple(
10031003
inh.model for model in only_models for inh in for_each_inherit(cr, model, skip_inherit)
10041004
)
@@ -1008,6 +1008,34 @@ def adapt_dict(d):
10081008
)
10091009

10101010

1011+
# adapt depends for custom compute fields
1012+
def adapt_depends(cr, model, old, new):
1013+
if not column_exists(cr, "ir_model_fields", "depends"):
1014+
# this field only appears in 9.0
1015+
return
1016+
1017+
target_model = model
1018+
1019+
match_old = r"\y{}\y".format(re.escape(old))
1020+
cr.execute(
1021+
"""
1022+
SELECT id, model, depends
1023+
FROM ir_model_fields
1024+
WHERE state = 'manual'
1025+
AND depends ~ %s
1026+
""",
1027+
[match_old],
1028+
)
1029+
for id_, model, depends in cr.fetchall():
1030+
temp_depends = depends.split(",")
1031+
for i in range(len(temp_depends)):
1032+
domain = _adapt_one_domain(cr, target_model, old, new, model, [(temp_depends[i], "=", "depends")])
1033+
temp_depends[i] = domain[0][0] if domain else temp_depends[i]
1034+
new_depends = ",".join(temp_depends)
1035+
if new_depends != depends:
1036+
cr.execute("UPDATE ir_model_fields SET depends = %s WHERE id = %s", [new_depends, id_])
1037+
1038+
10111039
def adapt_related(cr, model, old, new, skip_inherit=()):
10121040
_validate_model(model)
10131041

0 commit comments

Comments
 (0)