update add script upgrade : ir.cron + jsonrcp-to-rpc
All checks were successful
Setup Native Action / native (3.12.7) (push) Has been skipped
Setup Native Action / docker (3.12.7) (push) Has been skipped

This commit is contained in:
KaySar12 2025-03-10 17:50:47 +07:00
parent 232b00e719
commit fe1cac9656
4 changed files with 187 additions and 2 deletions

View File

@ -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:

@ -1 +1 @@
Subproject commit 9cd8fcda7914a865acf1d9a57365a7fce7e29998
Subproject commit 008bfa6a561e9d3012b5ab7164743c433737a2bc

View File

@ -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 <field name='numbercall'> and <field name='doall'> within <record model='ir.cron'> 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 <record model="ir.cron"> blocks and remove specified fields
record_cron_re = re.compile(
r"""
(<record\s+[^>]*model="ir\.cron"[^>]*>) # Capture opening <record model="ir.cron"> with attributes
( # Start capturing content
.*? # Any content before fields (non-greedy)
(?: # Non-capturing group for fields to remove
<field\s+name="numbercall"[^>]*> # Match <field name="numbercall"> with any content
.*? # Content inside field
</field> # Closing tag
| # OR
<field\s+name="numbercall"[^>]*> # Match unclosed <field name="numbercall">
| # OR
<field\s+name="numbercall"[^>]*\/> # Match self-closing <field name="numbercall">
| # OR
<field\s+name="doall"[^>]*> # Match <field name="doall"> with any content
.*? # Content inside field
</field> # Closing tag
| # OR
<field\s+name="doall"[^>]*> # Match unclosed <field name="doall">
| # OR
<field\s+name="doall"[^>]*\/> # Match self-closing <field name="doall">
)
.*? # Any content after fields (non-greedy)
)
(</record>) # Capture closing </record>
""",
re.VERBOSE | re.DOTALL,
)
def clean_record(match):
"""Replace function to remove numbercall and doall fields."""
opening_tag = match.group(1) # <record model="ir.cron" ...>
content = match.group(2) # Content between tags
closing_tag = match.group(3) # </record>
# Patterns for fields to remove within the content
field_patterns = [
r'<field\s+name="numbercall"[^>]*>.*?</field>', # Standard field
r'<field\s+name="numbercall"[^>]*>', # Unclosed field
r'<field\s+name="numbercall"[^>]*\/>', # Self-closing field
r'<field\s+name="doall"[^>]*>.*?</field>', # Standard field
r'<field\s+name="doall"[^>]*>', # Unclosed field
r'<field\s+name="doall"[^>]*\/>', # 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 <record model="ir.cron"> 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 <record model='ir.cron'> in {file.path}"
)
else:
logger.debug(f"No changes needed in {file.path}")
file_manager.print_progress(fileno, len(files))

View File

@ -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))