From 3c646645e09856bc8dfe7c3a747d18af02ca3fab Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 10 Nov 2023 13:14:45 +0100 Subject: [PATCH 1/2] [IMP] util/inherit.py: leverage the new `ir.model.inherit` model Since odoo/odoo@35e22b8fe906d26618ebbc02583f980f7fa20e42, the inheritance tree is reflected into the database. So for upgrade from version 17, we can use this instead of the harcoded tree. --- src/base/tests/test_util.py | 4 ++++ src/util/inherit.py | 45 +++++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/base/tests/test_util.py b/src/base/tests/test_util.py index 7d5860347..8d9c4ef4b 100644 --- a/src/base/tests/test_util.py +++ b/src/base/tests/test_util.py @@ -469,6 +469,10 @@ def test_model_table_convertion(self): self.assertEqual(util.model_of_table(cr, table), model) +@unittest.skipIf( + util.version_gte("saas~17.1"), + "Starting Odoo 17, the info being stored in the database, the test can't lie about its base version", +) class TestInherit(UnitTestCase): @classmethod def setUpClass(cls): diff --git a/src/util/inherit.py b/src/util/inherit.py index 9d4910e72..057ed4027 100644 --- a/src/util/inherit.py +++ b/src/util/inherit.py @@ -3,13 +3,50 @@ import operator import os -from ._inherit import inheritance_data from .const import ENVIRON -from .misc import parse_version +from .misc import _cached, parse_version, version_gte _logger = logging.getLogger(__name__) +if version_gte("saas~17.1"): + from ._inherit import Inherit, frozendict + + @_cached + def _get_inheritance_data(cr): + base_version = _get_base_version(cr)[:2] + ("*final",) + cr.execute( + """ + SELECT p.model, + array_agg(m.model ORDER BY i.id), + array_agg(f.name ORDER BY i.id) + FROM ir_model_inherit i + JOIN ir_model m + ON m.id = i.model_id + JOIN ir_model p + ON p.id = i.parent_id + LEFT JOIN ir_model_fields f + ON f.id = i.parent_field_id + GROUP BY p.model + """ + ) + return frozendict( + { + parent: [ + Inherit(model=model, born=base_version, dead=None, via=via) + for model, via in zip(children, vias, strict=True) + ] + for parent, children, vias in cr.fetchall() + } + ) + +else: + from ._inherit import inheritance_data + + def _get_inheritance_data(cr): + return inheritance_data + + def _get_base_version(cr): # base_version is normaly computed in `base/0.0.0/pre-base_version.py` (and symlinks) # However, if theses scripts are used to upgrade custom modules afterward (like the P.S. do), @@ -49,7 +86,7 @@ def for_each_inherit(cr, model, skip=(), interval="[)"): if skip == "*": return cmp_ = _version_comparator(cr, interval) - for inh in inheritance_data.get(model, []): + for inh in _get_inheritance_data(cr).get(model, []): if inh.model in skip: continue if cmp_(inh): @@ -61,7 +98,7 @@ def inherit_parents(cr, model, skip=(), interval="[)"): return skip = set(skip) cmp_ = _version_comparator(cr, interval) - for parent, inhs in inheritance_data.items(): + for parent, inhs in _get_inheritance_data(cr).items(): if parent in skip: continue for inh in inhs: From fe4710c3b078ca8abae2e6b9f46af0e44475c24c Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 13 Nov 2023 10:34:36 +0100 Subject: [PATCH 2/2] [FIX] tools/generate-inherit.py: stop at branch `17.0` After this version, the data are reflected into the database. --- tools/generate-inherit.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/generate-inherit.py b/tools/generate-inherit.py index 7de0acbd2..b88998b99 100755 --- a/tools/generate-inherit.py +++ b/tools/generate-inherit.py @@ -129,10 +129,10 @@ def apply_on(self, version: Version) -> bool: return self.born <= version < self.dead -_NEXT_MAJOR = 18 -_VERSIONS = {Version(f"{major}.0") for major in range(7, _NEXT_MAJOR)} +_LAST_MAJOR = 17 +_VERSIONS = {Version(f"{major}.0") for major in range(7, _LAST_MAJOR + 1)} _VERSIONS |= {Version(f"saas-{saas}") for saas in range(1, 19)} -_VERSIONS |= {Version(f"saas-{major}.{minor}") for major in range(11, _NEXT_MAJOR) for minor in range(1, 6)} +_VERSIONS |= {Version(f"saas-{major}.{minor}") for major in range(11, _LAST_MAJOR) for minor in range(1, 6)} VERSIONS = sorted(_VERSIONS)