From fe1cac96567c60b44713029825a446b33f923a29 Mon Sep 17 00:00:00 2001 From: KaySar12 Date: Mon, 10 Mar 2025 17:50:47 +0700 Subject: [PATCH] update add script upgrade : ir.cron + jsonrcp-to-rpc --- Makefile | 2 +- extra-addons | 2 +- odoo/upgrade_code/17.5-04-ir-cron.py | 89 +++++++++++++++++++ odoo/upgrade_code/17.5-05-jsonrpc-to-rpc.py | 96 +++++++++++++++++++++ 4 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 odoo/upgrade_code/17.5-04-ir-cron.py create mode 100644 odoo/upgrade_code/17.5-05-jsonrpc-to-rpc.py diff --git a/Makefile b/Makefile index 023735b45..f28ac0856 100644 --- a/Makefile +++ b/Makefile @@ -87,7 +87,7 @@ cleanup_addons: install_modules: ${PYTHON} odoo-bin --config=${CONFIG} -d ${DATABASE} -i ${MODULES} --xmlrpc-port=${PORT} upgrade_modules: - ${PYTHON} odoo-bin upgrade_code --addons-path=${UPGRADE_DIR} --from ${OLD_VER} --to ${NEW_VER} --dry-run + ${PYTHON} odoo-bin upgrade_code --script ${SCRIPTS} --addons-path=${UPGRADE_DIR} || true ##### Docker Deployment ######### run_test_docker: diff --git a/extra-addons b/extra-addons index 9cd8fcda7..008bfa6a5 160000 --- a/extra-addons +++ b/extra-addons @@ -1 +1 @@ -Subproject commit 9cd8fcda7914a865acf1d9a57365a7fce7e29998 +Subproject commit 008bfa6a561e9d3012b5ab7164743c433737a2bc diff --git a/odoo/upgrade_code/17.5-04-ir-cron.py b/odoo/upgrade_code/17.5-04-ir-cron.py new file mode 100644 index 000000000..845db8b54 --- /dev/null +++ b/odoo/upgrade_code/17.5-04-ir-cron.py @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- + +import re +from pathlib import Path +import logging + +# Set up logging +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + + +def upgrade(file_manager): + """Remove and within in XML files.""" + # Filter files to only XML files + files = [file for file in file_manager if file.path.suffix == ".xml"] + if not files: + logger.info("No XML files found to process") + return + + # Regex pattern to match blocks and remove specified fields + record_cron_re = re.compile( + r""" + (]*model="ir\.cron"[^>]*>) # Capture opening with attributes + ( # Start capturing content + .*? # Any content before fields (non-greedy) + (?: # Non-capturing group for fields to remove + ]*> # Match with any content + .*? # Content inside field + # Closing tag + | # OR + ]*> # Match unclosed + | # OR + ]*\/> # Match self-closing + | # OR + ]*> # Match with any content + .*? # Content inside field + # Closing tag + | # OR + ]*> # Match unclosed + | # OR + ]*\/> # Match self-closing + ) + .*? # Any content after fields (non-greedy) + ) + () # Capture closing + """, + re.VERBOSE | re.DOTALL, + ) + + def clean_record(match): + """Replace function to remove numbercall and doall fields.""" + opening_tag = match.group(1) # + content = match.group(2) # Content between tags + closing_tag = match.group(3) # + + # Patterns for fields to remove within the content + field_patterns = [ + r']*>.*?', # Standard field + r']*>', # Unclosed field + r']*\/>', # Self-closing field + r']*>.*?', # Standard field + r']*>', # Unclosed field + r']*\/>', # Self-closing field + ] + + # Remove all matching fields + for pattern in field_patterns: + content = re.sub(pattern, "", content, flags=re.DOTALL) + + return f"{opening_tag}{content}{closing_tag}" + + # Process each file + for fileno, file in enumerate(files, start=1): + content = file.content + original_content = content + + # Replace matching blocks + content = record_cron_re.sub(clean_record, content) + + # Only update if changes were made + if content != original_content: + file.content = content + logger.info( + f"Removed numbercall/doall fields in in {file.path}" + ) + else: + logger.debug(f"No changes needed in {file.path}") + + file_manager.print_progress(fileno, len(files)) diff --git a/odoo/upgrade_code/17.5-05-jsonrpc-to-rpc.py b/odoo/upgrade_code/17.5-05-jsonrpc-to-rpc.py new file mode 100644 index 000000000..fcaebe691 --- /dev/null +++ b/odoo/upgrade_code/17.5-05-jsonrpc-to-rpc.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- + +import re +from pathlib import Path +import logging + +# Set up logging +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + + +def upgrade(file_manager): + """Replace 'import { jsonrpc } from "@web/core/network/rpc_service";' with 'import { rpc } from "@web/core/network/rpc";' in JS files.""" + # Filter files to only JavaScript files + files = [file for file in file_manager if file.path.suffix in (".js", ".jsx")] + if not files: + logger.info("No JavaScript files found to process") + return + + # Regex pattern to match the specific import statement + jsonrpc_import_re = re.compile( + r""" + ^\s* # Start of line with optional whitespace + import\s+ # 'import' keyword + \{\s*jsonrpc\s*\}\s+ # '{ jsonrpc }' with optional whitespace + from\s+ # 'from' keyword + "@web/core/network/rpc_service" # Exact module path + \s*;\s*$ # Semicolon and optional whitespace to end of line + """, + re.VERBOSE | re.MULTILINE, # MULTILINE for line-by-line matching + ) + # Regex pattern to match jsonrpc( calls + jsonrpc_call_re = re.compile( + r""" + \bjsonrpc\s* # 'jsonrpc' followed by optional whitespace + \( # Opening parenthesis + """, + re.VERBOSE, + ) + + # Replacement string + replacement = 'import { rpc } from "@web/core/network/rpc";' + + # Process each file + for fileno, file in enumerate(files, start=1): + content = file.content + original_content = content + + # Replace the import statement + content = jsonrpc_import_re.sub(replacement, content) + content = jsonrpc_call_re.sub("rpc(", content) + # Only update if changes were made + if content != original_content: + file.content = content + logger.info(f"Updated import statement in {file.path}") + else: + logger.debug(f"No changes needed in {file.path}") + + file_manager.print_progress(fileno, len(files)) + + +# Example usage (for testing) +if __name__ == "__main__": + from types import SimpleNamespace + + class MockFile: + def __init__(self, path, content): + self.path = Path(path) + self.content = content + + class MockFileManager: + def __init__(self, files): + self.files = files + + def __iter__(self): + return iter(self.files) + + def print_progress(self, current, total): + print(f"Progress: {current}/{total}") + + # Test data + sample_files = [ + MockFile( + "test1.js", + 'import { jsonrpc } from "@web/core/network/rpc_service";\nconsole.log("test");', + ), + MockFile( + "test2.js", + 'import {jsonrpc} from "@web/core/network/rpc_service";\nlet x = 5;', + ), + MockFile( + "test3.js", + 'import { something } from "@other/module";\nconsole.log("no change");', + ), + ] + upgrade(MockFileManager(sample_files))