Skip to content

[18.0] pending prs #1

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

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
78ff2a4
[ADD] replace action.read() by _for_xml_id to avoid access rights issue
anothingguy Oct 26, 2023
68218c6
[ADD] Add error message chart_template_ref argument has been removed …
lef-adhoc Oct 17, 2024
ad33392
[IMP] remove depcreate class `oe_kanban_global_click` and `oe_kanban_…
Nov 20, 2024
33bdf2e
[IMP] remove deprecated `oe_kanban_colorpicker` and warning deprecate…
Nov 20, 2024
9fa9b67
[IMP] remove deprecated kanban-tooltip
Nov 21, 2024
ba0e1d7
[IMP] warning deprecated kanban_image
Nov 21, 2024
c3d4cfa
[IMP] Changed type='edit' to type='open' to open records
Nov 21, 2024
e88dc86
[IMP] slugify deprecation
xaviedoanhduy Oct 21, 2024
6f1d833
[ADD] add error messages in cron deleted fields
lef-adhoc Oct 17, 2024
c24e530
[ADD] @string in xpath is deprecated error
unaiberis Aug 23, 2024
85a4c27
[ADD] renamed fields case for l10n_mx
CLaurelB Oct 25, 2024
a09141b
[IMP] replace editable attribute on list view
xaviedoanhduy Oct 24, 2024
7665612
[IMP] automatically remove @odoo-module from js assets
xaviedoanhduy Oct 23, 2024
dfa841b
[FIX] By not putting the comma it does not take it as a tuple and the…
lef-adhoc Oct 28, 2024
2d4f004
[IMP] Add error messages for deprecated 'registry' usage and imports
lef-adhoc Oct 29, 2024
880fac7
[IMP] Add error messages for deprecated '_name_search' method, replac…
lef-adhoc Oct 29, 2024
492b938
[IMP] Add error messages for deprecated '_check_recursion' and '_chec…
lef-adhoc Oct 29, 2024
49ed426
[IMP] Add warning for direct '_' import in translations
lef-adhoc Nov 1, 2024
c251da2
[IMP] _() improvements
chaule97 Oct 30, 2024
814e12c
[IMP] *: Add warning for auto-added invisible/readonly fields in XML …
lef-adhoc Nov 13, 2024
0973b86
[IMP] remove string attribute in tree view
anothingguy Nov 14, 2024
f87799a
[IMP] replace toggle_button to boolean_toggle widget
xaviedoanhduy Nov 15, 2024
7a3aece
[ADD] odoo_module_migrate: Deprecated kanban-box-card-menu
zaoral Nov 15, 2024
842eb63
Merge remote-tracking branch 'nhant/improve-kanban-arch' into 18.0-pe…
Nov 26, 2024
0d73b13
Merge remote-tracking branch 'anothingguy/imp_ref_action_pattern' int…
Nov 26, 2024
48f9003
update splugify
Nov 26, 2024
8ce71dd
[IMP] remove unaccent in Char field
Nov 22, 2024
1030e09
[IMP] tools.get_file to support single extension
xaviedoanhduy Nov 27, 2024
3ada970
[fix] fix get_files method
Nov 27, 2024
6b23df0
[UPG] Base migration upgrade for fields rename.
Sep 30, 2024
3df69e7
Merge branch 'imp-get_files' into 18.0-pending-prs
Jan 20, 2025
7f00653
Merge branch 'remove-unaccent-in-field' into 18.0-pending-prs
Jan 20, 2025
5229f11
Merge branch 'upg-add-field-rename' into 18.0-pending-prs
Jan 20, 2025
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
32 changes: 28 additions & 4 deletions odoo_module_migrate/base_migration_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
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
Expand Down Expand Up @@ -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)
Expand Down
32 changes: 31 additions & 1 deletion odoo_module_migrate/migration_scripts/migrate_130_140.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,36 @@ def reformat_deprecated_tags(
logger.debug("Reformatted files:\n" f"{list(reformatted_files)}")


def refactor_action_read(**kwargs):
"""
replace action.read() by _for_xml_id to avoid access rights issue

##### case 1: pattern for case action.read[0] right after self.env.ref
## action = self.env.ref('sale.action_orders')
## action = action.read()[0]

##### case 2: pattern for case having new line between action.read[0] and self.env.ref
## action = self.env.ref('sale.action_orders')
## .........
## .........
## action = action.read()[0]
"""
logger = kwargs["logger"]
tools = kwargs["tools"]
module_path = kwargs["module_path"]
file_paths = _get_files(module_path, ".py")

old_term = r"action.*= self.env.ref\((.*)\)((\n.+)+?)?(\n.+)(action\.read\(\)\[0\])"
new_term = r'\2\4self.env["ir.actions.act_window"]._for_xml_id(\1)'
for file_path in file_paths:
logger.debug(f"refactor file {file_path}")
tools._replace_in_file(
file_path,
{old_term: new_term},
log_message="refactor action.read[0] to _for_xml_id",
)


_TEXT_REPLACES = {
".js": {
r"tour\.STEPS\.SHOW_APPS_MENU_ITEM": "tour.stepUtils.showAppsMenuItem()",
Expand All @@ -155,5 +185,5 @@ def reformat_deprecated_tags(

class MigrationScript(BaseMigrationScript):

_GLOBAL_FUNCTIONS = [reformat_deprecated_tags]
_GLOBAL_FUNCTIONS = [reformat_deprecated_tags, refactor_action_read]
_TEXT_REPLACES = _TEXT_REPLACES
83 changes: 83 additions & 0 deletions odoo_module_migrate/migration_scripts/migrate_130_allways.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import re
from odoo_module_migrate.base_migration_script import BaseMigrationScript


def multi_value_translation_replacement_function(match, single_quote=True):
format_string = match.group(1)
dictionary_entries = match.group(2)

formatted_entries = []
for entry in dictionary_entries.split(","):
if ":" in entry:
[key, value] = entry.split(":")
formatted_entries.append(
"{}={}".format(key.strip().strip("'").strip('"'), value.strip())
)

formatted_entries = ", ".join(formatted_entries)

if single_quote:
return f"_('{format_string}', {formatted_entries})"
return f'_("{format_string}", {formatted_entries})'


def format_parenthesis(match):
format_string = match.group(1)
dictionary_entries = match.group(2)

if dictionary_entries.endswith(","):
dictionary_entries = dictionary_entries[:-1]

return f"_({format_string}, {dictionary_entries})"


def format_replacement_function(match, single_quote=True):
format_string = re.sub(r"\{\d*\}", "%s", match.group(1))
format_string = re.sub(r"{(\w+)}", r"%(\1)s", format_string)
arguments = " ".join(match.group(2).split())

if arguments.endswith(","):
arguments = arguments[:-1]

if single_quote:
return f"_('{format_string}', {arguments})"
return f'_("{format_string}", {arguments})'


def replace_translation_function(
logger, module_path, module_name, manifest_path, migration_steps, tools
):
files_to_process = tools.get_files(module_path, (".py",))

replaces = {
r'_\(\s*"([^"]+)"\s*\)\s*%\s*\{([^}]+)\}': lambda match: multi_value_translation_replacement_function(
match, single_quote=False
),
r"_\(\s*'([^']+)'\s*\)\s*%\s*\{([^}]+)\}": lambda match: multi_value_translation_replacement_function(
match, single_quote=True
),
r'_\((["\'].*?%[ds].*?["\'])\)\s*%\s*\(\s*(.+)\s*\)': format_parenthesis,
r'_\((["\'].*?%[ds].*?["\'])\)\s*?%\s*?([^\s]+)': r"_(\1, \2)",
r'_\(\s*"([^"]*)"\s*\)\.format\(\s*(\s*[^)]+)\)': lambda match: format_replacement_function(
match, single_quote=False
),
r"_\(\s*'([^']*)'\s*\)\.format\(\s*(\s*[^)]+)\)": lambda match: format_replacement_function(
match, single_quote=True
),
}

for file in files_to_process:
try:
tools._replace_in_file(
file,
replaces,
log_message=f"""Improve _() function: {file}""",
)
except Exception as e:
logger.error(f"Error processing file {file}: {str(e)}")


class MigrationScript(BaseMigrationScript):

_GLOBAL_FUNCTIONS = [replace_translation_function]
28 changes: 28 additions & 0 deletions odoo_module_migrate/migration_scripts/migrate_150_allways.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo_module_migrate.base_migration_script import BaseMigrationScript


def replace_toggle_button(
logger, module_path, module_name, manifest_path, migration_steps, tools
):
files_to_process = tools.get_files(module_path, (".xml",))
replaces = {
r'widget="\s*toggle_button\s*"': 'widget="boolean_toggle"',
r"widget='\s*toggle_button\s*'": 'widget="boolean_toggle"',
r'<attribute\s+name=["\']widget["\']>\s*toggle_button\s*</attribute>': '<attribute name="widget">boolean_toggle</attribute>',
}

for file in files_to_process:
try:
tools._replace_in_file(
file,
replaces,
log_message=f"Replace toggle_button widget to boolean_toggle widget in file: {file}",
)
except Exception as e:
logger.error(f"Error processing file {file}: {str(e)}")


class MigrationScript(BaseMigrationScript):
_GLOBAL_FUNCTIONS = [replace_toggle_button]
Loading