Skip to content

Commit b18e530

Browse files
author
BT-dherreros
committed
[UPG] Base migration upgrade for fields rename.
1 parent 9014d66 commit b18e530

25 files changed

Lines changed: 133 additions & 25 deletions

File tree

odoo_module_migrate/base_migration_script.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,15 @@ def process_file(
208208
replaces.update(self._TEXT_REPLACES.get(extension, {}))
209209
replaces.update(renamed_models.get("replaces"))
210210
replaces.update(removed_models.get("replaces"))
211-
212-
new_text = tools._replace_in_file(
211+
tools._replace_in_file(
213212
absolute_file_path, replaces, "Change file content of %s" % filename
214213
)
214+
field_renames = renamed_fields.get("replaces")
215+
# To be safe we only rename fields on files associated with the current replaces
216+
if field_renames:
217+
new_text = tools._replace_field_names(
218+
absolute_file_path, field_renames, "Updated field names of %s" % filename
219+
)
215220

216221
# Display errors if the new content contains some obsolete
217222
# pattern
@@ -260,17 +265,32 @@ def handle_renamed_fields(self, removed_fields):
260265
For now this handler is simple but the idea would be to improve it
261266
with deeper analysis and direct replaces if it is possible and secure.
262267
For that analysis model_name could be used
268+
It also will add to the replaces key of the returned dictionary a key value pair
269+
to be used in _replace_in_file
263270
"""
264-
res = {}
271+
res = {"warnings": {}, "replaces": {}}
272+
res['replaces'] = {}
265273
for model_name, old_field_name, new_field_name, more_info in removed_fields:
274+
# if model_name in res['replaces']:
275+
# res['replaces'][model_name].update({old_field_name: new_field_name,})
276+
# else:
277+
res["replaces"].update(
278+
{
279+
model_name: {old_field_name: new_field_name,}
280+
}
281+
)
266282
msg = "On the model %s, the field %s was renamed to %s.%s" % (
267283
model_name,
268284
old_field_name,
269285
new_field_name,
270286
" %s" % more_info if more_info else "",
271287
)
272-
res[r"""(['"]{0}['"]|\.{0}[\s,=])""".format(old_field_name)] = msg
273-
return {"warnings": res}
288+
res["warnings"].update(
289+
{
290+
r"""(['"]{0}['"]|\.{0}[\s,=])""".format(old_field_name): msg,
291+
}
292+
)
293+
return res
274294

275295
def handle_deprecated_modules(self, manifest_path, deprecated_modules):
276296
current_manifest_text = tools._read_content(manifest_path)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- ['mail.template', 'user_signature', 'Commit https://github.com/odoo/odoo/commit/de1743ab']
1+
- ["mail.template", "user_signature", "Commit https://github.com/odoo/odoo/commit/de1743ab"]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- ['account.move.line', 'exclude_from_invoice_tab', 'Commit https://github.com/odoo/odoo/commit/d8d47f9ff8554f4b39487fd2f13c153c7d6f958d']
1+
- ["account.move.line", "exclude_from_invoice_tab", "Commit https://github.com/odoo/odoo/commit/d8d47f9ff8554f4b39487fd2f13c153c7d6f958d"]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- ['product.product', 'price', 'Commit https://github.com/odoo/odoo/commit/9e99a9df464d97a74ca320d']
1+
- ["product.product", "price", "Commit https://github.com/odoo/odoo/commit/9e99a9df464d97a74ca320d"]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- ['hr.expense', 'reference', 'Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a']
1+
- ["hr.expense", "reference", "Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- ["account.invoice", "Commit https://github.com/odoo/odoo/commit/bc131c0cfb51c953de8ec41fb820c8c7831eefb5"]
2+
- ["account.invoice.line", "Commit https://github.com/odoo/odoo/commit/bc131c0cfb51c953de8ec41fb820c8c7831eefb5"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- ["stock.inventory", "Commit https://github.com/brain-tec/odoo/commit/bdcb3d192be1e01e1141aa09c60027337009a67b"]
2+
- ["stock.inventory.line", "Commit https://github.com/brain-tec/odoo/commit/bdcb3d192be1e01e1141aa09c60027337009a67b"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- ["account.invoice.report", "product_qty", "quantity", "Commit https://github.com/odoo/odoo/commit/bc131c0cfb51c953de8ec41fb820c8c7831eefb5"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- ["image.mixin", "image_original", "image_1920", "Commit https://github.com/odoo/odoo/commit/58a2ffa26f1a3b0f9630ce16d11b758d18e20a21"]
2+
- ["mail.channel", "image", "image_128", "Commit https://github.com/odoo/odoo/commit/f0ffbea17381cb117f2eed4ea18a76e2b0f37f00"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- ["hr.plan.activity.type", "name", "summary", "Commit https://github.com/odoo/odoo/commit/58a2ffa26f1a3b0f9630ce16d11b758d18e20a21"]

0 commit comments

Comments
 (0)