Skip to content

Commit c852d63

Browse files
thni-odooKangOl
authored andcommitted
[FIX] util/fields: update depends on rename
We needs to update custom fields `depends` definition. closes #21 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 80865ec commit c852d63

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/util/fields.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ def adapt_dict(d):
10111011
# skip all inherit, they will be handled by the resursive call
10121012
adapt_domains(cr, model, old, new, adapter=domain_adapter, skip_inherit="*", force_adapt=True)
10131013
adapt_related(cr, model, old, new, skip_inherit="*")
1014+
adapt_depends(cr, model, old, new, skip_inherit="*")
10141015

10151016
inherited_models = tuple(
10161017
inh.model for model in only_models for inh in for_each_inherit(cr, model, skip_inherit)
@@ -1021,6 +1022,41 @@ def adapt_dict(d):
10211022
)
10221023

10231024

1025+
def adapt_depends(cr, model, old, new, skip_inherit=()):
1026+
# adapt depends for custom compute fields only. Standard fields will be updated by the ORM.
1027+
_validate_model(model)
1028+
1029+
if not column_exists(cr, "ir_model_fields", "depends"):
1030+
# this field only appears in 9.0
1031+
return
1032+
1033+
target_model = model
1034+
1035+
match_old = r"\y{}\y".format(re.escape(old))
1036+
cr.execute(
1037+
"""
1038+
SELECT id, model, depends
1039+
FROM ir_model_fields
1040+
WHERE state = 'manual'
1041+
AND depends ~ %s
1042+
""",
1043+
[match_old],
1044+
)
1045+
for id_, model, depends in cr.fetchall():
1046+
temp_depends = depends.split(",")
1047+
for i in range(len(temp_depends)):
1048+
domain = _adapt_one_domain(cr, target_model, old, new, model, [(temp_depends[i], "=", "depends")])
1049+
if domain:
1050+
temp_depends[i] = domain[0][0]
1051+
new_depends = ",".join(temp_depends)
1052+
if new_depends != depends:
1053+
cr.execute("UPDATE ir_model_fields SET depends = %s WHERE id = %s", [new_depends, id_])
1054+
1055+
# down on inherits
1056+
for inh in for_each_inherit(cr, target_model, skip_inherit):
1057+
adapt_depends(cr, inh.model, old, new, skip_inherit=skip_inherit)
1058+
1059+
10241060
def adapt_related(cr, model, old, new, skip_inherit=()):
10251061
_validate_model(model)
10261062

0 commit comments

Comments
 (0)