From 533f7982c8ea956f04b2e5ef82cab9458b55b41f Mon Sep 17 00:00:00 2001 From: KaySar12 Date: Sat, 12 Apr 2025 15:55:53 +0700 Subject: [PATCH] update --- cli/module.py | 5 ++++- scripts/modules_management.py | 17 ++++++++++++----- services/odoo/module.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/cli/module.py b/cli/module.py index d6d0982..7c80565 100644 --- a/cli/module.py +++ b/cli/module.py @@ -7,7 +7,7 @@ import lib.color_log as color_log def setup_cli(subparsers): module_parser = subparsers.add_parser("module", help="Manage instance module") module_parser.add_argument( - "action", choices=["install", "uninstall", "upgrade"], help="Module action" + "action", choices=["install", "uninstall", "upgrade","update_list"], help="Module action" ) module_parser.add_argument("instance", type=str, help="Instance Name") module_parser.add_argument( @@ -36,6 +36,9 @@ def module(args): for module_name in args.modules: try: match args.action: + case "update_list": + pbar.set_description(f"Installing {module_name}") + module_manager.update_list(args.instance) case "install": pbar.set_description(f"Installing {module_name}") module_manager.install(args.instance, [module_name]) diff --git a/scripts/modules_management.py b/scripts/modules_management.py index ec4b368..7cf5b71 100644 --- a/scripts/modules_management.py +++ b/scripts/modules_management.py @@ -68,7 +68,7 @@ def update_instance(instance_name, action, force_pull=False): color_log.Show("INFO", f"\n=== Starting update process for {instance_name} ===") # 1. Pull latest code - color_log.Show("INFO", "Step 1/3: Pulling latest code...") + color_log.Show("INFO", "Step 1/4: Pulling latest code...") pull_cmd = ["python", "utility/main.py", "git", "pull", instance_name] if force_pull: pull_cmd.append("--force") @@ -76,15 +76,22 @@ def update_instance(instance_name, action, force_pull=False): color_log.Show("WARNING", f"Skipping module update for {instance_name} due to pull failure") return False - # 2. Update modules - color_log.Show("INFO", "Step 2/3: Updating modules...") + # 2. Update module list + color_log.Show("INFO", "Step 2/4: Updating module list...") + module_list_cmd = ["python", "utility/main.py", "module", "update_list", instance_name] + if not run_command(module_list_cmd, f"Updating module list for {instance_name}"): + color_log.Show("WARNING", f"Module list update failed for {instance_name}") + return False + + # 3. Update modules + color_log.Show("INFO", "Step 3/4: Updating modules...") module_cmd = ["python", "utility/main.py", "module", action, instance_name] if not run_command(module_cmd, f"Updating modules for {instance_name}"): color_log.Show("WARNING", f"Module update failed for {instance_name}") return False - # 3. Restart service - color_log.Show("INFO", "Step 3/3: Restarting service...") + # 4. Restart service + color_log.Show("INFO", "Step 4/4: Restarting service...") restart_cmd = ["python", "utility/main.py", "service", "restart", instance_name] if not run_command(restart_cmd, f"Restarting service for {instance_name}"): color_log.Show("WARNING", f"Service restart failed for {instance_name}") diff --git a/services/odoo/module.py b/services/odoo/module.py index ef15d64..df9df07 100644 --- a/services/odoo/module.py +++ b/services/odoo/module.py @@ -86,6 +86,34 @@ class OdooModuleManager: """Upgrade multiple modules for the specified instance(s).""" self._manage_module("upgrade", instance_name, module_names) + def update_list(self, instance_name: str = None) -> dict: + """Update the module list and return the number of updated and added modules. + + Args: + instance_name (str): Name of the Odoo instance to update modules for + + Returns: + dict: Dictionary containing the number of updated and added modules + """ + self.config.connect(instance_name) + try: + updated, added = self.config.execute( + instance_name, + "ir.module.module", + "update_list", + ) + color_log.Show( + "OK", + f"Module list updated successfully in {instance_name}. Updated: {updated}, Added: {added}", + ) + return {"updated": updated, "added": added} + except Exception as e: + color_log.Show( + "FAILED", + f"Error updating module list in {instance_name}: {e}", + ) + return {"updated": 0, "added": 0} + def is_module_installed(self, instance_name: str, module_name: str) -> bool: """Check if a module is installed in the specified instance.