diff --git a/upgrade_analysis/__init__.py b/upgrade_analysis/__init__.py
index ca02278df..172ae9a25 100644
--- a/upgrade_analysis/__init__.py
+++ b/upgrade_analysis/__init__.py
@@ -2,6 +2,5 @@ from . import odoo_patch
from . import models
from . import wizards
from . import blacklist
-from . import apriori
from . import compare
from . import upgrade_log
diff --git a/upgrade_analysis/apriori.py b/upgrade_analysis/apriori.py
deleted file mode 100644
index 4c06538e2..000000000
--- a/upgrade_analysis/apriori.py
+++ /dev/null
@@ -1,31 +0,0 @@
-""" Encode any known changes to the database here
-to help the matching process
-"""
-
-import logging
-
-_logger = logging.getLogger(__name__)
-
-
-try:
- from odoo.addons.openupgrade_scripts.apriori import merged_modules, renamed_modules
-except ImportError:
- renamed_modules = {}
- merged_modules = {}
- _logger.warning(
- "You are using upgrade_analysis without having"
- " openupgrade_scripts module available."
- " The analysis process will not work properly,"
- " if you are generating analysis for the odoo modules"
- " in an openupgrade context."
- )
-
-renamed_modules.update({})
-
-merged_modules.update({})
-
-# only used here for upgrade_analysis
-renamed_models = {}
-
-# only used here for upgrade_analysis
-merged_models = {}
diff --git a/upgrade_analysis/compare.py b/upgrade_analysis/compare.py
index 6af14263d..bc817d9e0 100644
--- a/upgrade_analysis/compare.py
+++ b/upgrade_analysis/compare.py
@@ -11,7 +11,19 @@
import collections
import copy
-from . import apriori
+try:
+ from odoo.addons.openupgrade_scripts import apriori
+except ImportError:
+ from dataclasses import dataclass, field
+
+ @dataclass
+ class NullApriori:
+ renamed_modules: dict = field(default_factory=dict)
+ merged_modules: dict = field(default_factory=dict)
+ renamed_models: dict = field(default_factory=dict)
+ merged_models: dict = field(default_factory=dict)
+
+ apriori = NullApriori()
def module_map(module):
diff --git a/upgrade_analysis/models/ir_module_module.py b/upgrade_analysis/models/ir_module_module.py
index a9a569517..bff4265b3 100644
--- a/upgrade_analysis/models/ir_module_module.py
+++ b/upgrade_analysis/models/ir_module_module.py
@@ -24,6 +24,9 @@ class UpgradeAttribute(models.Model):
def _compute_is_odoo_module(self):
for module in self:
module_path = get_module_path(module.name)
+ if not module_path:
+ module.is_odoo_module = False
+ continue
absolute_repo_path = os.path.split(module_path)[0]
x, relative_repo_path = os.path.split(absolute_repo_path)
module.is_odoo_module = relative_repo_path == "addons"
diff --git a/upgrade_analysis/models/upgrade_analysis.py b/upgrade_analysis/models/upgrade_analysis.py
index b0463e9f2..f42ffdff1 100644
--- a/upgrade_analysis/models/upgrade_analysis.py
+++ b/upgrade_analysis/models/upgrade_analysis.py
@@ -5,7 +5,6 @@
import logging
import os
-from pathlib import Path
from odoo import fields, models
from odoo.exceptions import UserError
@@ -18,11 +17,6 @@ from .. import compare
_logger = logging.getLogger(__name__)
_IGNORE_MODULES = ["openupgrade_records", "upgrade_analysis"]
-try:
- from odoo.addons.openupgrade_scripts import apriori
-except ImportError:
- apriori = False
-
class UpgradeAnalysis(models.Model):
_name = "upgrade.analysis"
@@ -42,28 +36,28 @@ class UpgradeAnalysis(models.Model):
log = fields.Text(readonly=True)
upgrade_path = fields.Char(
- default=lambda x: x._default_upgrade_path(),
+ compute="_compute_upgrade_path",
+ readonly=True,
help=(
"The base file path to save the analyse files of Odoo modules. "
- "Default is taken from Odoo's --upgrade-path command line option. "
+ "Taken from Odoo's --upgrade-path command line option or the "
+ "'scripts' subdirectory in the openupgrade_scripts addon."
),
- required=True,
)
-
write_files = fields.Boolean(
help="Write analysis files to the module directories", default=True
)
- def _default_upgrade_path(self):
- # Return upgrade_path value, if exists
- config_value = config.get("upgrade_path", False)
- if config_value:
- return config_value
- # Otherwise, try to guess, with the openupgrade_scripts path
- elif apriori:
- apriori_path = Path(os.path.abspath(apriori.__file__))
- return os.path.join(apriori_path.parent, "scripts")
- return False
+ def _compute_upgrade_path(self):
+ """Return the --upgrade-path configuration option or the `scripts`
+ directory in `openupgrade_scripts` if available
+ """
+ res = config.get("upgrade_path", False)
+ if not res:
+ module_path = get_module_path("openupgrade_scripts", display_warning=False)
+ if module_path:
+ res = os.path.join(module_path, "scripts")
+ self.upgrade_path = res
def _get_remote_model(self, connection, model):
self.ensure_one()
@@ -79,13 +73,16 @@ class UpgradeAnalysis(models.Model):
):
module = self.env["ir.module.module"].search([("name", "=", module_name)])[0]
if module.is_odoo_module:
- module_path = os.path.join(self.upgrade_path, module_name)
- full_path = os.path.join(module_path, version)
+ if not self.upgrade_path:
+ return (
+ "ERROR: no upgrade_path set when writing analysis of %s\n"
+ % module_name
+ )
+ full_path = os.path.join(self.upgrade_path, module_name, version)
else:
- module_path = get_module_path(module_name)
- full_path = os.path.join(module_path, "migrations", version)
- if not module_path:
- return "ERROR: could not find module path of '%s':\n" % (module_name)
+ full_path = os.path.join(
+ get_module_path(module_name, "migrations", version)
+ )
if not os.path.exists(full_path):
try:
os.makedirs(full_path)
@@ -116,11 +113,6 @@ class UpgradeAnalysis(models.Model):
}
)
- if not self.upgrade_path:
- return (
- "ERROR: no upgrade_path set when writing analysis of %s\n" % module_name
- )
-
connection = self.config_id.get_connection()
RemoteRecord = self._get_remote_model(connection, "record")
LocalRecord = self.env["upgrade.record"]
@@ -183,6 +175,17 @@ class UpgradeAnalysis(models.Model):
+ local_model_records
}
)
+ if "base" in affected_modules:
+ try:
+ from odoo.addons.openupgrade_scripts import apriori
+ except ImportError:
+ _logger.error(
+ "You are using upgrade_analysis on core modules without "
+ " having openupgrade_scripts module available."
+ " The analysis process will not work properly,"
+ " if you are generating analysis for the odoo modules"
+ " in an openupgrade context."
+ )
# reorder and output the result
keys = ["general"] + affected_modules
diff --git a/upgrade_analysis/views/view_upgrade_analysis.xml b/upgrade_analysis/views/view_upgrade_analysis.xml
index c2ce39170..c664fa70d 100644
--- a/upgrade_analysis/views/view_upgrade_analysis.xml
+++ b/upgrade_analysis/views/view_upgrade_analysis.xml
@@ -38,7 +38,7 @@
/>