diff --git a/odoo_module_migrate/base_migration_script.py b/odoo_module_migrate/base_migration_script.py
index f42e792c..56226db9 100644
--- a/odoo_module_migrate/base_migration_script.py
+++ b/odoo_module_migrate/base_migration_script.py
@@ -208,10 +208,17 @@ def process_file(
replaces.update(self._TEXT_REPLACES.get(extension, {}))
replaces.update(renamed_models.get("replaces"))
replaces.update(removed_models.get("replaces"))
-
- new_text = tools._replace_in_file(
+ tools._replace_in_file(
absolute_file_path, replaces, "Change file content of %s" % filename
)
+ field_renames = renamed_fields.get("replaces")
+ # To be safe we only rename fields on files associated with the current replaces
+ if field_renames:
+ new_text = tools._replace_field_names(
+ absolute_file_path,
+ field_renames,
+ "Updated field names of %s" % filename,
+ )
# Display errors if the new content contains some obsolete
# pattern
@@ -260,17 +267,34 @@ def handle_renamed_fields(self, removed_fields):
For now this handler is simple but the idea would be to improve it
with deeper analysis and direct replaces if it is possible and secure.
For that analysis model_name could be used
+ It also will add to the replaces key of the returned dictionary a key value pair
+ to be used in _replace_in_file
"""
- res = {}
+ res = {"warnings": {}, "replaces": {}}
+ res["replaces"] = {}
for model_name, old_field_name, new_field_name, more_info in removed_fields:
+ # if model_name in res['replaces']:
+ # res['replaces'][model_name].update({old_field_name: new_field_name,})
+ # else:
+ res["replaces"].update(
+ {
+ model_name: {
+ old_field_name: new_field_name,
+ }
+ }
+ )
msg = "On the model %s, the field %s was renamed to %s.%s" % (
model_name,
old_field_name,
new_field_name,
" %s" % more_info if more_info else "",
)
- res[r"""(['"]{0}['"]|\.{0}[\s,=])""".format(old_field_name)] = msg
- return {"warnings": res}
+ res["warnings"].update(
+ {
+ r"""(['"]{0}['"]|\.{0}[\s,=])""".format(old_field_name): msg,
+ }
+ )
+ return res
def handle_deprecated_modules(self, manifest_path, deprecated_modules):
current_manifest_text = tools._read_content(manifest_path)
diff --git a/odoo_module_migrate/migration_scripts/removed_fields/migrate_130_140/mail.yaml b/odoo_module_migrate/migration_scripts/removed_fields/migrate_130_140/mail.yaml
index 181be944..4715fdba 100644
--- a/odoo_module_migrate/migration_scripts/removed_fields/migrate_130_140/mail.yaml
+++ b/odoo_module_migrate/migration_scripts/removed_fields/migrate_130_140/mail.yaml
@@ -1 +1 @@
-- ['mail.template', 'user_signature', 'Commit https://github.com/odoo/odoo/commit/de1743ab']
+- ["mail.template", "user_signature", "Commit https://github.com/odoo/odoo/commit/de1743ab"]
diff --git a/odoo_module_migrate/migration_scripts/removed_fields/migrate_150_160/account.yaml b/odoo_module_migrate/migration_scripts/removed_fields/migrate_150_160/account.yaml
index f9e8d781..2fb665a2 100644
--- a/odoo_module_migrate/migration_scripts/removed_fields/migrate_150_160/account.yaml
+++ b/odoo_module_migrate/migration_scripts/removed_fields/migrate_150_160/account.yaml
@@ -1 +1 @@
-- ['account.move.line', 'exclude_from_invoice_tab', 'Commit https://github.com/odoo/odoo/commit/d8d47f9ff8554f4b39487fd2f13c153c7d6f958d']
+- ["account.move.line", "exclude_from_invoice_tab", "Commit https://github.com/odoo/odoo/commit/d8d47f9ff8554f4b39487fd2f13c153c7d6f958d"]
diff --git a/odoo_module_migrate/migration_scripts/removed_fields/migrate_150_160/product.yaml b/odoo_module_migrate/migration_scripts/removed_fields/migrate_150_160/product.yaml
index e968aac1..cbe90e6e 100644
--- a/odoo_module_migrate/migration_scripts/removed_fields/migrate_150_160/product.yaml
+++ b/odoo_module_migrate/migration_scripts/removed_fields/migrate_150_160/product.yaml
@@ -1 +1 @@
-- ['product.product', 'price', 'Commit https://github.com/odoo/odoo/commit/9e99a9df464d97a74ca320d']
+- ["product.product", "price", "Commit https://github.com/odoo/odoo/commit/9e99a9df464d97a74ca320d"]
diff --git a/odoo_module_migrate/migration_scripts/removed_fields/migrate_160_170/hr.yaml b/odoo_module_migrate/migration_scripts/removed_fields/migrate_160_170/hr.yaml
index 00ef5d9a..a98917a7 100644
--- a/odoo_module_migrate/migration_scripts/removed_fields/migrate_160_170/hr.yaml
+++ b/odoo_module_migrate/migration_scripts/removed_fields/migrate_160_170/hr.yaml
@@ -1 +1 @@
-- ['hr.expense', 'reference', 'Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a']
+- ["hr.expense", "reference", "Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a"]
diff --git a/odoo_module_migrate/migration_scripts/removed_models/migrate_120_130/removed_models.yaml b/odoo_module_migrate/migration_scripts/removed_models/migrate_120_130/removed_models.yaml
new file mode 100644
index 00000000..ff246f0a
--- /dev/null
+++ b/odoo_module_migrate/migration_scripts/removed_models/migrate_120_130/removed_models.yaml
@@ -0,0 +1,2 @@
+- ["account.invoice", "Commit https://github.com/odoo/odoo/commit/bc131c0cfb51c953de8ec41fb820c8c7831eefb5"]
+- ["account.invoice.line", "Commit https://github.com/odoo/odoo/commit/bc131c0cfb51c953de8ec41fb820c8c7831eefb5"]
diff --git a/odoo_module_migrate/migration_scripts/removed_models/migrate_140_150/removed_models.yaml b/odoo_module_migrate/migration_scripts/removed_models/migrate_140_150/removed_models.yaml
new file mode 100644
index 00000000..b46935aa
--- /dev/null
+++ b/odoo_module_migrate/migration_scripts/removed_models/migrate_140_150/removed_models.yaml
@@ -0,0 +1,2 @@
+- ["stock.inventory", "Commit https://github.com/brain-tec/odoo/commit/bdcb3d192be1e01e1141aa09c60027337009a67b"]
+- ["stock.inventory.line", "Commit https://github.com/brain-tec/odoo/commit/bdcb3d192be1e01e1141aa09c60027337009a67b"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/account.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/account.yaml
new file mode 100644
index 00000000..4091ccc5
--- /dev/null
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/account.yaml
@@ -0,0 +1 @@
+- ["account.invoice.report", "product_qty", "quantity", "Commit https://github.com/odoo/odoo/commit/bc131c0cfb51c953de8ec41fb820c8c7831eefb5"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/base.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/base.yaml
new file mode 100644
index 00000000..27ca737b
--- /dev/null
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/base.yaml
@@ -0,0 +1,2 @@
+- ["image.mixin", "image_original", "image_1920", "Commit https://github.com/odoo/odoo/commit/58a2ffa26f1a3b0f9630ce16d11b758d18e20a21"]
+- ["mail.channel", "image", "image_128", "Commit https://github.com/odoo/odoo/commit/f0ffbea17381cb117f2eed4ea18a76e2b0f37f00"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/hr.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/hr.yaml
new file mode 100644
index 00000000..5e33122e
--- /dev/null
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/hr.yaml
@@ -0,0 +1 @@
+- ["hr.plan.activity.type", "name", "summary", "Commit https://github.com/odoo/odoo/commit/58a2ffa26f1a3b0f9630ce16d11b758d18e20a21"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/inventory.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/inventory.yaml
new file mode 100644
index 00000000..a417621a
--- /dev/null
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/inventory.yaml
@@ -0,0 +1 @@
+- ["product.attribute", "type", "display_type", "Commit https://github.com/odoo/odoo/commit/58a2ffa26f1a3b0f9630ce16d11b758d18e20a21"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/payment.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/payment.yaml
new file mode 100644
index 00000000..d5c1ec20
--- /dev/null
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_120_130/payment.yaml
@@ -0,0 +1 @@
+- ["payment.acquirer", "image", "image_128", "Commit https://github.com/odoo/odoo/commit/f0ffbea17381cb117f2eed4ea18a76e2b0f37f00"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_130_140/account.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_130_140/account.yaml
index e05b1cda..f8f37307 100644
--- a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_130_140/account.yaml
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_130_140/account.yaml
@@ -1,3 +1,4 @@
-- ['account.move', 'type', 'move_type', 'Commit https://github.com/odoo/odoo/commit/d675dbaa4c7174591e0e7c1a3caf3e76877312ce']
-- ['account.move', 'invoice_payment_state', 'payment_state', 'Commit https://github.com/odoo/odoo/commit/8e4158af810bcf475214946fa64d3b0ce4d3b26d']
-- ['account.move', 'invoice_sent', 'is_move_sent', 'Commit https://github.com/odoo/odoo/commit/caeb782841fc5a7ad71a196e2c9ee67644ef9074']
+- ["account.move", "type", "move_type", "Commit https://github.com/odoo/odoo/commit/d675dbaa4c7174591e0e7c1a3caf3e76877312ce"]
+- ["account.move", "invoice_payment_state", "payment_state", "Commit https://github.com/odoo/odoo/commit/8e4158af810bcf475214946fa64d3b0ce4d3b26d"]
+- ["account.move", "invoice_sent", "is_move_sent", "Commit https://github.com/odoo/odoo/commit/caeb782841fc5a7ad71a196e2c9ee67644ef9074"]
+- ["account.bank.statement.line", "name", "payment_ref", "Commit https://github.com/odoo/odoo/commit/f3fe2d50d99698eb0261c2309bd63f9f64b3d703"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_130_140/company.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_130_140/company.yaml
new file mode 100644
index 00000000..e537b6dd
--- /dev/null
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_130_140/company.yaml
@@ -0,0 +1 @@
+- ["res.company", "accrual_default_journal_id", "automatic_entry_default_journal_id", "Commit https://github.com/odoo/odoo/commit/0ea9254c81ea42a7fd9af455f05d70e3ca227460"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_140_150/calendar.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_140_150/calendar.yaml
new file mode 100644
index 00000000..c5d84d12
--- /dev/null
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_140_150/calendar.yaml
@@ -0,0 +1,4 @@
+- ["calendar.event", "mo", "mon", "Commit https://github.com/odoo/odoo/commit/7fb9c8129606538b004dea4e6ad071eabf6c6fb1"]
+- ["calendar.event", "we", "wed", "Commit https://github.com/odoo/odoo/commit/7fb9c8129606538b004dea4e6ad071eabf6c6fb1"]
+- ["calendar.recurrence", "mo", "mon", "Commit https://github.com/odoo/odoo/commit/7fb9c8129606538b004dea4e6ad071eabf6c6fb1"]
+- ["calendar.recurrence", "we", "wed", "Commit https://github.com/odoo/odoo/commit/7fb9c8129606538b004dea4e6ad071eabf6c6fb1"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_140_150/payment.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_140_150/payment.yaml
new file mode 100644
index 00000000..75484fdb
--- /dev/null
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_140_150/payment.yaml
@@ -0,0 +1 @@
+- ["payment.transaction", "date", "last_state_change", "Commit https://github.com/odoo/odoo/commit/f3fe2d50d99698eb0261c2309bd63f9f64b3d703"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/account.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/account.yaml
index d0a2a63c..ce904656 100644
--- a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/account.yaml
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/account.yaml
@@ -1,3 +1,4 @@
-- ['account.account', 'user_type_id', 'account_type', 'Commit https://github.com/odoo/odoo/commit/26b2472f4977ccedbb0b5ed5f']
-- ['account.account', 'internal_type', 'account_type', 'Commit https://github.com/odoo/odoo/commit/26b2472f4977ccedbb0b5ed5f08be2c04313fd21']
-- ['account.move.line', 'analytic_account_id', 'analytic_distribution', 'Commit https://github.com/odoo/odoo/commit/7064c95aa04e5138bb12ae97acfee04ebb67cc0e']
+- ["account.account", "user_type_id", "account_type", "Commit https://github.com/odoo/odoo/commit/26b2472f4977ccedbb0b5ed5f"]
+- ["account.account", "internal_type", "account_type", "Commit https://github.com/odoo/odoo/commit/26b2472f4977ccedbb0b5ed5f08be2c04313fd21"]
+- ["account.move.line", "analytic_account_id", "analytic_distribution", "Commit https://github.com/odoo/odoo/commit/7064c95aa04e5138bb12ae97acfee04ebb67cc0e"]
+- ["account.analytic.line", "move_id", "move_line_id", "Commit https://github.com/odoo/odoo/commit/7fb9c8129606538b004dea4e6ad071eabf6c6fb1"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/hr.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/hr.yaml
index e301c1b5..6be12d68 100644
--- a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/hr.yaml
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/hr.yaml
@@ -1 +1 @@
-- ['hr.expense', 'analytic_account_id', 'analytic_distribution', 'Commit https://github.com/odoo/odoo/commit/7e3403068fc3fbc40182b3cfeb80e97a9300e8ff']
+- ["hr.expense", "analytic_account_id", "analytic_distribution", "Commit https://github.com/odoo/odoo/commit/7e3403068fc3fbc40182b3cfeb80e97a9300e8ff"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/inventory.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/inventory.yaml
new file mode 100644
index 00000000..c3aac4ea
--- /dev/null
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/inventory.yaml
@@ -0,0 +1 @@
+- ["product.supplierinfo", "name", "partner_id", "Commit https://github.com/odoo/odoo/commit/f3fe2d50d99698eb0261c2309bd63f9f64b3d703"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/payment.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/payment.yaml
new file mode 100644
index 00000000..dc30bbfa
--- /dev/null
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/payment.yaml
@@ -0,0 +1 @@
+- ["payment.token", "name", "payment_details", "Commit https://github.com/odoo/odoo/commit/c1b41bcd08ea26032904b3fdd34d743f4342ac62"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/stock.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/stock.yaml
index 7eda4428..90c1e87f 100644
--- a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/stock.yaml
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/stock.yaml
@@ -1 +1 @@
-- ['stock.move.line', 'product_qty', 'reserved_qty', 'Commit https://github.com/odoo/odoo/commit/56e7bcf0cb88acf3d60420569ab3eea9bdb19bdb']
+- ["stock.move.line", "product_qty", "reserved_qty", "Commit https://github.com/odoo/odoo/commit/56e7bcf0cb88acf3d60420569ab3eea9bdb19bdb"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/utm.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/utm.yaml
new file mode 100644
index 00000000..becbcba4
--- /dev/null
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_150_160/utm.yaml
@@ -0,0 +1 @@
+- ["utm.campaign", "name", "title", "Commit https://github.com/brain-tec/odoo/commit/4dbcefb5e5b1878e81fe9be9fe48a785f813334f"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_160_170/hr.yaml b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_160_170/hr.yaml
index 7b42cf8f..8222e7cc 100644
--- a/odoo_module_migrate/migration_scripts/renamed_fields/migrate_160_170/hr.yaml
+++ b/odoo_module_migrate/migration_scripts/renamed_fields/migrate_160_170/hr.yaml
@@ -1,7 +1,7 @@
-- ['hr.expense', 'total_amount', 'total_amount_currency', 'Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a']
-- ['hr.expense', 'unit_amount', 'price_unit', 'Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a']
-- ['hr.expense', 'amount_tax', 'tax_amount_currency', 'Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a']
-- ['hr.expense', 'untaxed_amount', 'untaxed_amount_currency', 'Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a']
-- ['hr.expense', 'total_amount_company', 'total_amount', 'Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a']
-- ['hr.expense', 'sheet_is_editable', 'is_editable', 'Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a']
-- ['hr.expense', 'attachment_number', 'nb_attachment', 'Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a']
+- ["hr.expense", "total_amount", "total_amount_currency", "Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a"]
+- ["hr.expense", "unit_amount", "price_unit", "Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a"]
+- ["hr.expense", "amount_tax", "tax_amount_currency", "Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a"]
+- ["hr.expense", "untaxed_amount", "untaxed_amount_currency", "Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a"]
+- ["hr.expense", "total_amount_company", "total_amount", "Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a"]
+- ["hr.expense", "sheet_is_editable", "is_editable", "Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a"]
+- ["hr.expense", "attachment_number", "nb_attachment", "Commit https://github.com/odoo/odoo/commit/68fbdc964038ef6a1cf0d3df773db101ca81794a"]
diff --git a/odoo_module_migrate/migration_scripts/renamed_models/migrate_150_160/renamed_models.yaml b/odoo_module_migrate/migration_scripts/renamed_models/migrate_150_160/renamed_models.yaml
index eba0e19f..53491415 100644
--- a/odoo_module_migrate/migration_scripts/renamed_models/migrate_150_160/renamed_models.yaml
+++ b/odoo_module_migrate/migration_scripts/renamed_models/migrate_150_160/renamed_models.yaml
@@ -1 +1 @@
-- ["stock.production.lot", "stock.lot", None]
+- ["stock.production.lot", "stock.lot", "c1b41bcd08ea26032904b3fdd34d743f4342ac62"]
diff --git a/odoo_module_migrate/tools.py b/odoo_module_migrate/tools.py
index 7618bcc4..21dfd206 100644
--- a/odoo_module_migrate/tools.py
+++ b/odoo_module_migrate/tools.py
@@ -5,11 +5,19 @@
import subprocess
import re
import pathlib
+from lxml import etree
+from dataclasses import fields
from .config import _AVAILABLE_MIGRATION_STEPS
from .log import logger
+CLASS_PATTERN = re.compile(
+ r"(class\s+\w+\s*\(\s*(?:\w+\.)?\w+(?:,\s*(?:\w+\.)?\w+)*\)\s*:\s*(?:\n\s+.*)+)",
+ re.MULTILINE,
+)
+
+
def _get_available_init_version_names():
return [x["init_version_name"] for x in _AVAILABLE_MIGRATION_STEPS]
@@ -65,6 +73,46 @@ def _replace_in_file(file_path, replaces, log_message=False):
return new_text
+def _replace_field_names(file_path, replaces, log_message=False):
+ current_text = _read_content(file_path)
+ new_text = current_text
+ # if the field is a python file with _inherit = model_name or model.name
+ # we try to replace the fields
+ model = get_model(file_path)
+ if model in replaces:
+ model_field_name_replaces = replaces[model]
+ # This replace is more careful on when and where we do replaces because the idea is to only change field
+ # names instead of everywhere (i.e. changing move_type to type affects the arch type on xml files)
+ if ".xml" in file_path:
+ # replace only between inside the arch tags
+ xml_data_bytes = new_text.encode("utf-8")
+ root = etree.fromstring(xml_data_bytes)
+ archs = root.xpath('.//field[@name="arch"]')
+ # 3 looped for, not a good look
+ for arch in archs:
+ for tag in arch:
+ for old_term, new_term in model_field_name_replaces.items():
+ new_tag = etree.fromstring(
+ etree.tostring(tag).decode().replace(old_term, new_term)
+ )
+ arch.replace(tag, new_tag)
+ new_text = etree.tostring(
+ root, pretty_print=True, xml_declaration=True, encoding="UTF-8"
+ ).decode()
+ elif ".py" in file_path:
+ # replace only inside of classes
+ for old_term, new_term in model_field_name_replaces.items():
+ new_text = replace_in_classes(new_text, old_term, new_term)
+
+ # Write file if changed
+ if new_text != current_text:
+ if not log_message:
+ log_message = "Changing content of file: %s" % file_path.name
+ logger.info(log_message)
+ _write_content(file_path, new_text)
+ return new_text
+
+
def get_files(module_path, extensions):
"""
Returns a list of files with the specified extensions within the module_path.
@@ -79,3 +127,31 @@ def get_files(module_path, extensions):
file_paths.extend(module_dir.rglob(f"*{ext}"))
return file_paths
+
+
+def get_model(absolute_filepath):
+ model = ""
+ match = ""
+ with open(absolute_filepath, "r") as file:
+ file_content = file.read()
+ if "xml" in absolute_filepath:
+ match = re.search(
+ r"([a-zA-Z0-9_.]+)", file_content
+ )
+ elif "py" in absolute_filepath:
+ match = re.search(r"_inherit\s*=\s*['\"]([^'\"]+)['\"]", file_content)
+ if match:
+ model = match.group(1)
+ return model
+
+
+def replace_in_classes(code, old_text, new_text):
+ # Find all classes in the code
+ classes = CLASS_PATTERN.findall(code)
+
+ # Replace old_text with new_text in each class body
+ for cls in classes:
+ updated_class = cls.replace(old_text, new_text)
+ code = code.replace(cls, updated_class)
+
+ return code