From 7de18509c60d9b8fd8e4a8ebafae4c1765b288f9 Mon Sep 17 00:00:00 2001 From: mreficent Date: Sat, 27 Mar 2021 00:44:50 +0100 Subject: [PATCH] [FIX] upgrade_analysis: fix methods related to noupdate data --- upgrade_analysis/__manifest__.py | 3 +- upgrade_analysis/models/upgrade_analysis.py | 30 +++++++++++-------- upgrade_analysis/models/upgrade_record.py | 9 +++--- upgrade_analysis/readme/CONTRIBUTORS.rst | 2 +- .../static/description/index.html | 2 +- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/upgrade_analysis/__manifest__.py b/upgrade_analysis/__manifest__.py index 62d019b39..ee70913e1 100644 --- a/upgrade_analysis/__manifest__.py +++ b/upgrade_analysis/__manifest__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Upgrade Analysis", - "summary": "performs a difference analysis between modules" + "summary": "Performs a difference analysis between modules" " installed on two different Odoo instances", "version": "14.0.2.0.1", "category": "Migration", @@ -19,6 +19,7 @@ "wizards/view_upgrade_install_wizard.xml", ], "installable": True, + "depends": ["base"], "external_dependencies": { "python": ["dataclasses", "odoorpc", "openupgradelib"], }, diff --git a/upgrade_analysis/models/upgrade_analysis.py b/upgrade_analysis/models/upgrade_analysis.py index 15e08e7ca..26038249f 100644 --- a/upgrade_analysis/models/upgrade_analysis.py +++ b/upgrade_analysis/models/upgrade_analysis.py @@ -1,6 +1,6 @@ # Copyright 2011-2015 Therp BV # Copyright 2016-2020 Opener B.V. -# Copyright 2019 Eficent +# Copyright 2019 ForgeFlow # Copyright 2020 GRAP # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # flake8: noqa: C901 @@ -19,9 +19,10 @@ from odoo.tools.convert import nodeattr2bool from odoo.tools.translate import _ try: - from odoo.addons.openupgrade_scripts.apriori import renamed_modules + from odoo.addons.openupgrade_scripts.apriori import merged_modules, renamed_modules except ImportError: renamed_modules = {} + merged_modules = {} from .. import compare @@ -73,7 +74,7 @@ class UpgradeAnalysis(models.Model): def _get_remote_model(self, connection, model): self.ensure_one() if model == "record": - if float(self.config_id.version) < 14: + if float(self.config_id.version) < 14.0: return connection.env["openupgrade.record"] else: return connection.env["upgrade.record"] @@ -407,30 +408,31 @@ class UpgradeAnalysis(models.Model): target_dict[xml_id] = record @classmethod - def _parse_files(self, xml_files, module_name): + def _parse_paths(self, xml_paths, module_name): records_update = {} records_noupdate = {} parser = etree.XMLParser( remove_blank_text=True, strip_cdata=False, ) - for xml_file in xml_files: + for xml_path in xml_paths: try: # This is for a final correct pretty print # Ref.: https://stackoverflow.com/a/7904066 # Also don't strip CDATA tags as needed for HTML content - root_node = etree.fromstring(xml_file.encode("utf-8"), parser=parser) + tree = etree.parse(xml_path, parser=parser) except etree.XMLSyntaxError: continue # Support xml files with root Element either odoo or openerp # Condition: each xml file should have only one root element # {, or —rarely— }; + root_node = tree.getroot() root_node_noupdate = nodeattr2bool(root_node, "noupdate", False) if root_node.tag not in ("openerp", "odoo", "data"): raise ValidationError( _( "Unexpected root Element: %s in file: %s" - % (root_node.getroot(), xml_file) + % (tree.getroot(), xml_path) ) ) for node in root_node: @@ -460,15 +462,17 @@ class UpgradeAnalysis(models.Model): local_record_obj = self.env["upgrade.record"] local_modules = local_record_obj.list_modules() for remote_module in remote_record_obj.list_modules(): - local_module = renamed_modules.get(remote_module, remote_module) + local_module = renamed_modules.get( + remote_module, merged_modules.get(remote_module, remote_module) + ) if local_module not in local_modules: continue - remote_files = remote_record_obj.get_xml_records(remote_module) - local_files = local_record_obj.get_xml_records(local_module) - remote_update, remote_noupdate = self._parse_files( - remote_files, remote_module + remote_paths = remote_record_obj.get_xml_records(remote_module) + local_paths = local_record_obj.get_xml_records(local_module) + remote_update, remote_noupdate = self._parse_paths( + remote_paths, remote_module ) - local_update, local_noupdate = self._parse_files(local_files, local_module) + local_update, local_noupdate = self._parse_paths(local_paths, local_module) diff = self._get_xml_diff( remote_update, remote_noupdate, local_update, local_noupdate ) diff --git a/upgrade_analysis/models/upgrade_record.py b/upgrade_analysis/models/upgrade_record.py index c31b453ea..fdcd0e707 100644 --- a/upgrade_analysis/models/upgrade_record.py +++ b/upgrade_analysis/models/upgrade_record.py @@ -1,6 +1,6 @@ # Copyright 2011-2015 Therp BV # Copyright 2016-2020 Opener B.V. -# Copyright 2019 Eficent +# Copyright 2019 ForgeFlow # Copyright 2020 GRAP # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -159,7 +159,7 @@ class UpgradeRecord(models.Model): # The order of the keys are important. # Load files in the same order as in # module/loading.py:load_module_graph - files = [] + paths = [] for key in ["init_xml", "update_xml", "data"]: if not manifest.get(key): continue @@ -167,6 +167,5 @@ class UpgradeRecord(models.Model): if not xml_file.lower().endswith(".xml"): continue parts = xml_file.split("/") - with open(os.path.join(addon_dir, *parts), "r") as xml_handle: - files.append(xml_handle.read()) - return files + paths.append(os.path.join(addon_dir, *parts)) + return paths diff --git a/upgrade_analysis/readme/CONTRIBUTORS.rst b/upgrade_analysis/readme/CONTRIBUTORS.rst index 5de0e93e5..b8c8505e9 100644 --- a/upgrade_analysis/readme/CONTRIBUTORS.rst +++ b/upgrade_analysis/readme/CONTRIBUTORS.rst @@ -3,5 +3,5 @@ * Pedro M. Baeza * Ferdinand Gassauer * Florent Xicluna -* Miquel Raïch +* Miquel Raïch * Sylvain LE GAL diff --git a/upgrade_analysis/static/description/index.html b/upgrade_analysis/static/description/index.html index 9d40422de..6a1087c8f 100644 --- a/upgrade_analysis/static/description/index.html +++ b/upgrade_analysis/static/description/index.html @@ -416,7 +416,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
  • Pedro M. Baeza <pedro.baeza@gmail.com>
  • Ferdinand Gassauer <gass@cc-l-12.chircar.at>
  • Florent Xicluna <florent.xicluna@gmail.com>
  • -
  • Miquel Raïch <miquel.raich@eficent.com>
  • +
  • Miquel Raïch <miquel.raich@forgeflow.com>
  • Sylvain LE GAL <https://twitter.com/legalsylvain>