diff --git a/odoo_module_migrate/migration_scripts/migrate_170_180.py b/odoo_module_migrate/migration_scripts/migrate_170_180.py index 930ebf72..871b5f31 100644 --- a/odoo_module_migrate/migration_scripts/migrate_170_180.py +++ b/odoo_module_migrate/migration_scripts/migrate_170_180.py @@ -100,8 +100,35 @@ def replace_user_has_groups( logger.error(f"Error processing file {file}: {str(e)}") +def replace_unaccent_parameter( + logger, module_path, module_name, manifest_path, migration_steps, tools +): + files_to_process = tools.get_files(module_path, (".py",)) + replaces = { + # Handle multiline with only unaccent=False + r"(?s)fields\.(Char|Text|Html|Properties)\(\s*unaccent\s*=\s*False\s*,?\s*\)": r"fields.\1()", + # Handle when unaccent=False is first parameter + r"(?s)fields\.(Char|Text|Html|Properties)\(\s*unaccent\s*=\s*False\s*,\s*([^)]+?)\)": r"fields.\1(\2)", + # Handle when unaccent=False is between other parameters + r"(?s)fields\.(Char|Text|Html|Properties)\(([^)]+?),\s*unaccent\s*=\s*False\s*,\s*([^)]+?)\)": r"fields.\1(\2, \3)", + # Handle when unaccent=False is the last parameter + r"(?s)fields\.(Char|Text|Html|Properties)\(([^)]+?),\s*unaccent\s*=\s*False\s*\)": r"fields.\1(\2)", + } + + for file in files_to_process: + try: + tools._replace_in_file( + file, + replaces, + log_message=f"[18.0] Removed deprecated unaccent=False parameter in file: {file}", + ) + except Exception as e: + logger.error(f"Error processing file {file}: {str(e)}") + + class MigrationScript(BaseMigrationScript): _GLOBAL_FUNCTIONS = [ + replace_unaccent_parameter, replace_tree_with_list_in_views, replace_chatter_blocks, replace_user_has_groups, diff --git a/tests/data_result/module_170_180/models/res_partner.py b/tests/data_result/module_170_180/models/res_partner.py index 21b4ba9d..30818f67 100644 --- a/tests/data_result/module_170_180/models/res_partner.py +++ b/tests/data_result/module_170_180/models/res_partner.py @@ -5,6 +5,11 @@ class ResPartner(models.Model): _inherit = "res.partner" test_field_1 = fields.Boolean() + test_unaccent = fields.Char(string="test_unaccent", default="test") + test_unaccent_only = fields.Char() + test_unaccent_only_html = fields.Html() + test_unaccent_multiline = fields.Char(string="test_unaccent", default="test") + test_unaccent_only_multiline = fields.Text() def example_method(self): self.env.ref('module_name.tree_view').write({'view_mode': 'list'}) diff --git a/tests/data_template/module_170/models/res_partner.py b/tests/data_template/module_170/models/res_partner.py index 36281105..52cdd201 100644 --- a/tests/data_template/module_170/models/res_partner.py +++ b/tests/data_template/module_170/models/res_partner.py @@ -5,6 +5,15 @@ class ResPartner(models.Model): _inherit = "res.partner" test_field_1 = fields.Boolean() + test_unaccent = fields.Char(string="test_unaccent", unaccent=False, default="test") + test_unaccent_only = fields.Char(unaccent=False) + test_unaccent_only_html = fields.Html(unaccent=False) + test_unaccent_multiline = fields.Char(string="test_unaccent", + unaccent=False, + default="test") + test_unaccent_only_multiline = fields.Text( + unaccent=False, + ) def example_method(self): self.env.ref('module_name.tree_view').write({'view_mode': 'tree'})