From aca06d6847d11f544b17fa13442cc8338ddd59f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Ra=C3=AFch?= Date: Thu, 15 Jan 2026 16:04:15 +0100 Subject: [PATCH] [IMP] upgrade_analysis: avoid "empty" analysis files Before this patch, sometimes analysis files were created for the modules doesnt' contain any "change". Let's avoid that. Besides other minor fixes, this patch improves the coverage file: No more "No DB layout changes" message on modules that contain the `noupdate_changes.xml` file. --- upgrade_analysis/models/upgrade_analysis.py | 41 ++++++++++--------- .../models/upgrade_comparison_config.py | 2 +- .../odoo/addons/base/models/ir_model.py | 4 ++ .../wizards/upgrade_install_wizard.py | 2 +- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/upgrade_analysis/models/upgrade_analysis.py b/upgrade_analysis/models/upgrade_analysis.py index d4ea3722227..36dccfd34e7 100644 --- a/upgrade_analysis/models/upgrade_analysis.py +++ b/upgrade_analysis/models/upgrade_analysis.py @@ -26,7 +26,12 @@ from .. import compare _logger = logging.getLogger(__name__) -_IGNORE_MODULES = ["openupgrade_records", "upgrade_analysis"] +_IGNORE_MODULES = [ + "openupgrade_records", + "upgrade_analysis", + "openupgrade_framework", + "openupgrade_scripts", +] class UpgradeAnalysis(models.Model): @@ -181,7 +186,7 @@ def analyze(self): remote_model_records, local_model_records ) - affected_modules = sorted( + affected_modules = list( { record["module"] for record in remote_records @@ -194,7 +199,7 @@ def analyze(self): ) if "base" in affected_modules: try: - pass + from odoo.addons.openupgrade_scripts import apriori # noqa: F401 except ImportError: _logger.error( "You are using upgrade_analysis on core modules without " @@ -205,21 +210,19 @@ def analyze(self): ) # reorder and output the result - keys = ["general"] + affected_modules modules = { module["name"]: module for module in self.env["ir.module.module"].search( [("state", "=", "installed")] ) } + keys = ["general"] + sorted( + (set(affected_modules) | set(modules.keys())) - set(_IGNORE_MODULES) + ) general_log = "" no_changes_modules = [] - for ignore_module in _IGNORE_MODULES: - if ignore_module in keys: - keys.remove(ignore_module) - for key in keys: contents = f"---Models in module '{key}'---\n" if key in res_model: @@ -245,8 +248,8 @@ def analyze(self): if compare.module_map(key) not in modules: general_log += f"---Probably obsolete module {key}---\n" + contents continue - if key not in modules: - # no need to log in full log the merged/renamed modules + if key not in modules or key in no_changes_modules: + # no need to log in full log the merged/renamed/unchanged modules continue if self.write_files: error = self._write_file(key, modules[key].installed_version, contents) @@ -264,12 +267,13 @@ def analyze(self): general_log, "upgrade_general_log.txt", ) - + noupdate_modules = [] try: - self.generate_noupdate_changes() + noupdate_modules = self.generate_noupdate_changes() except Exception as e: _logger.exception(f"Error generating noupdate changes: {e}") general_log += "ERROR: error when generating noupdate changes: {e}\n" + no_changes_modules = list(set(no_changes_modules) - set(noupdate_modules)) try: self.generate_module_coverage_file(no_changes_modules) except Exception as e: @@ -480,6 +484,7 @@ def generate_noupdate_changes(self): local_record_obj = self.env["upgrade.record"] local_modules = local_record_obj.list_modules() all_remote_modules = remote_record_obj.list_modules() + changed_modules = [] for local_module in local_modules: remote_files = [] remote_modules = [] @@ -508,13 +513,14 @@ def generate_noupdate_changes(self): module = self.env["ir.module.module"].search( [("name", "=", local_module)] ) + changed_modules.append(local_module) self._write_file( local_module, module.installed_version, diff, filename="noupdate_changes.xml", ) - return True + return changed_modules def generate_module_coverage_file(self, no_changes_modules): self.ensure_one() @@ -522,19 +528,14 @@ def generate_module_coverage_file(self, no_changes_modules): module_coverage_file_folder = config.get("module_coverage_file_folder", False) if not module_coverage_file_folder: - return + return False module_domain = [ ("state", "=", "installed"), ( "name", "not in", - [ - "upgrade_analysis", - "openupgrade_records", - "openupgrade_scripts", - "openupgrade_framework", - ], + _IGNORE_MODULES, ), ] diff --git a/upgrade_analysis/models/upgrade_comparison_config.py b/upgrade_analysis/models/upgrade_comparison_config.py index 7c84c38dc5c..d8bbe425e30 100644 --- a/upgrade_analysis/models/upgrade_comparison_config.py +++ b/upgrade_analysis/models/upgrade_comparison_config.py @@ -80,7 +80,7 @@ def test_connection(self): def new_analysis(self): self.ensure_one() - analysis = self.env["upgrade.analysis"].create({"config_id": self.id}) + analysis = self.env["upgrade.analysis"].create([{"config_id": self.id}]) return { "name": analysis._description, "view_mode": "form", diff --git a/upgrade_analysis/odoo_patch/odoo/addons/base/models/ir_model.py b/upgrade_analysis/odoo_patch/odoo/addons/base/models/ir_model.py index 48dbeedfee5..4c982ce849d 100644 --- a/upgrade_analysis/odoo_patch/odoo/addons/base/models/ir_model.py +++ b/upgrade_analysis/odoo_patch/odoo/addons/base/models/ir_model.py @@ -1,3 +1,5 @@ +import logging + # ruff: noqa from odoo import models @@ -6,6 +8,8 @@ from ...... import upgrade_log from .....odoo_patch import OdooPatch +_logger = logging.getLogger(__name__) + class IrModelConstraintPatch(OdooPatch): target = ir_model.IrModelConstraint diff --git a/upgrade_analysis/wizards/upgrade_install_wizard.py b/upgrade_analysis/wizards/upgrade_install_wizard.py index 3f2f4da3b07..d72d895f333 100644 --- a/upgrade_analysis/wizards/upgrade_install_wizard.py +++ b/upgrade_analysis/wizards/upgrade_install_wizard.py @@ -40,7 +40,7 @@ def _module_ids_domain(self, extra_domain=None): ] ) if extra_domain: - domain = Domain.AND(domain, extra_domain) + domain = Domain.AND([domain, extra_domain]) modules = self.env["ir.module.module"].search(domain) for start_pattern in BLACKLIST_MODULES_STARTS_WITH: