Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] remove unaccent in field #124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions odoo_module_migrate/migration_scripts/migrate_170_180.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions tests/data_result/module_170_180/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
Expand Down
9 changes: 9 additions & 0 deletions tests/data_template/module_170/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
Expand Down
Loading