@@ -996,6 +996,7 @@ def adapt_dict(d):
996996 # skip all inherit, they will be handled by the resursive call
997997 adapt_domains (cr , model , old , new , adapter = domain_adapter , skip_inherit = "*" , force_adapt = True )
998998 adapt_related (cr , model , old , new , skip_inherit = "*" )
999+ adapt_depends (cr , model , old , new , skip_inherit = "*" )
9991000
10001001 inherited_models = tuple (
10011002 inh .model for model in only_models for inh in for_each_inherit (cr , model , skip_inherit )
@@ -1006,6 +1007,41 @@ def adapt_dict(d):
10061007 )
10071008
10081009
1010+ # adapt depends for custom compute fields
1011+ def adapt_depends (cr , model , old , new , skip_inherit = ()):
1012+ _validate_model (model )
1013+
1014+ if not column_exists (cr , "ir_model_fields" , "depends" ):
1015+ # this field only appears in 9.0
1016+ return
1017+
1018+ target_model = model
1019+
1020+ match_old = r"\y{}\y" .format (re .escape (old ))
1021+ cr .execute (
1022+ """
1023+ SELECT id, model, depends
1024+ FROM ir_model_fields
1025+ WHERE state = 'manual'
1026+ AND depends ~ %s
1027+ """ ,
1028+ [match_old ],
1029+ )
1030+ for id_ , model , depends in cr .fetchall ():
1031+ temp_depends = depends .split ("," )
1032+ for i in range (len (temp_depends )):
1033+ domain = _adapt_one_domain (cr , target_model , old , new , model , [(temp_depends [i ], "=" , "depends" )])
1034+ if domain :
1035+ temp_depends [i ] = domain [0 ][0 ]
1036+ new_depends = "," .join (temp_depends )
1037+ if new_depends != depends :
1038+ cr .execute ("UPDATE ir_model_fields SET depends = %s WHERE id = %s" , [new_depends , id_ ])
1039+
1040+ # down on inherits
1041+ for inh in for_each_inherit (cr , target_model , skip_inherit ):
1042+ adapt_depends (cr , inh .model , old , new , skip_inherit = skip_inherit )
1043+
1044+
10091045def adapt_related (cr , model , old , new , skip_inherit = ()):
10101046 _validate_model (model )
10111047
0 commit comments