Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/base/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
45 changes: 41 additions & 4 deletions src/util/inherit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tools/generate-inherit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down