Skip to content

Commit 715d65a

Browse files
committed
[FIX] util/fields: ensure path update for ir_exports_line
Issue: When exporting data using the existing export template, a traceback error occurs. Cause: When a field is renamed, the path in `ir_exports_line` is not updated if it contains `.ids`. This happens because the resolve_model_fields_path fails to retrieve the field https://github.com/odoo/upgrade-util/blob/b7fbb070807f8393a0b5dbac274e1651d32b309d/src/util/helpers.py#L284-L319 record from `ir_model_fields` where the field name is `.id`, which leads to failing this condition because of the difference in length of old and new path https://github.com/odoo/upgrade-util/blob/b7fbb070807f8393a0b5dbac274e1651d32b309d/src/util/fields.py#L1026 closes #133 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 77db562 commit 715d65a

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/base/tests/test_util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ def setUp(self):
422422
(0, 0, {"name": "rate_ids/company_id/user_ids/name"}),
423423
(0, 0, {"name": "rate_ids/company_id/user_ids/partner_id/user_ids/name"}),
424424
(0, 0, {"name": "rate_ids/name"}),
425+
(0, 0, {"name": "rate_ids/company_id/user_ids/partner_id/user_ids/.id"}),
425426
],
426427
}
427428
]
@@ -438,6 +439,9 @@ def test_rename_field(self):
438439
self.assertEqual(
439440
self.export.export_fields[2].name, "rate_ids/company_id/user_ids/partner_id/renamed_user_ids/name"
440441
)
442+
self.assertEqual(
443+
self.export.export_fields[4].name, "rate_ids/company_id/user_ids/partner_id/renamed_user_ids/.id"
444+
)
441445

442446
util.rename_field(self.cr, "res.users", "name", "new_name")
443447
self._invalidate()

src/util/fields.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,13 +1088,19 @@ def _update_impex_renamed_fields_paths(cr, old_field_name, new_field_name, only_
10881088
continue
10891089
fixed_paths = {}
10901090
for record_id, related_model, path in cr.fetchall():
1091+
has_id = path[-1] == ".id"
1092+
if has_id:
1093+
path = path[:-1] # noqa: PLW2901
1094+
10911095
new_path = [
10921096
new_field_name
10931097
if field.field_name == old_field_name and field.field_model in only_models
10941098
else field.field_name
10951099
for field in resolve_model_fields_path(cr, related_model, path)
10961100
]
10971101
if len(new_path) == len(path) and new_path != path:
1102+
if has_id:
1103+
new_path.append(".id")
10981104
fixed_paths[record_id] = "/".join(new_path)
10991105
if fixed_paths:
11001106
cr.execute(

0 commit comments

Comments
 (0)