Skip to content

Commit b7b3679

Browse files
committed
[FIX] util/models: Fix compute for renamed model
if model got renamed during migration but related field of model compute didn't update due to that below traceback raised for fixing it replaced with according this [patch] (https://github.com/odoo/upgrade-util/blob/4230096526739591d15eb54652dc835ec8b3e3cc/src/util/models.py#L491) ``` 'fleet.fleet_vehicle_menu', 521, 'Fleet > Fleet > Fleet', 726): Traceback (most recent call last): File "/home/odoo/src/odoo/18.0/odoo/tools/safe_eval.py", line 397, in safe_eval return unsafe_eval(c, globals_dict, locals_dict) File "", line 2, in <module> File "/home/odoo/src/odoo/18.0/odoo/api.py", line 596, in __getitem__ return self.registry[model_name](self, (), ()) File "/home/odoo/src/odoo/18.0/odoo/modules/registry.py", line 240, in __getitem__ return self.models[model_name] KeyError: 'stock.production.lot' ``` UPG-2588678 OPW-4592615 closes #225 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 1c27407 commit b7b3679

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/util/models.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,24 @@ def remove_model(cr, model, drop_table=True, ignore_m2m=()):
250250
delete_model = remove_model
251251

252252

253+
def _replace_model_in_computed_custom_fields(cr, source, target):
254+
# adapt computes of manual fields
255+
if column_exists(cr, "ir_model_fields", "compute"):
256+
cr.execute(
257+
r"""
258+
UPDATE ir_model_fields
259+
SET compute = regexp_replace(compute, %s, %s, 'g')
260+
WHERE state = 'manual'
261+
AND compute IS NOT NULL
262+
AND name LIKE 'x\_%%'
263+
""",
264+
[
265+
r"""\yenv\[('|"){}\1\]""".format(re.escape(source)),
266+
"env['{}']".format(target),
267+
],
268+
)
269+
270+
253271
def rename_model(cr, old, new, rename_table=True):
254272
"""
255273
Rename a model.
@@ -375,6 +393,8 @@ def rename_model(cr, old, new, rename_table=True):
375393
""".format(col_prefix=col_prefix, old=old.replace(".", r"\."), new=new)
376394
)
377395

396+
_replace_model_in_computed_custom_fields(cr, old, new)
397+
378398

379399
def merge_model(cr, source, target, drop_table=True, fields_mapping=None, ignore_m2m=()):
380400
"""
@@ -487,21 +507,7 @@ def merge_model(cr, source, target, drop_table=True, fields_mapping=None, ignore
487507
else:
488508
cr.execute(fmt_query)
489509

490-
# adapt computes of manual fields
491-
if column_exists(cr, "ir_model_fields", "compute"):
492-
cr.execute(
493-
r"""
494-
UPDATE ir_model_fields
495-
SET compute = regexp_replace(compute, %s, %s, 'g')
496-
WHERE state = 'manual'
497-
AND compute IS NOT NULL
498-
AND name LIKE 'x\_%%'
499-
""",
500-
[
501-
r"""\yenv\[('|"){}\1\]""".format(re.escape(source)),
502-
"env['{}']".format(target),
503-
],
504-
)
510+
_replace_model_in_computed_custom_fields(cr, source, target)
505511

506512
# Adapt translations
507513
if table_exists(cr, "ir_translation"):

0 commit comments

Comments
 (0)