details: https://code.tryton.org/tryton/commit/1eca815d4df4
branch: default
user: Cédric Krier <[email protected]>
date: Wed Oct 28 15:14:37 2026 +0100
description:
Filter model names by more than one sets of subclasses
The resource mixin and inbound email needs to have only the models that
are
both subclass of ModelView and ModelStorage.
Closes #15176
diffstat:
modules/inbound_email/inbound_email.py | 3 ++-
trytond/trytond/ir/model.py | 15 +++++++++------
trytond/trytond/ir/resource.py | 2 +-
trytond/trytond/tests/resource.py | 6 +++---
4 files changed, 15 insertions(+), 11 deletions(-)
diffs (97 lines):
diff -r ccc9209a41cc -r 1eca815d4df4 modules/inbound_email/inbound_email.py
--- a/modules/inbound_email/inbound_email.py Sat Oct 31 14:25:54 2026 +0100
+++ b/modules/inbound_email/inbound_email.py Wed Oct 28 15:14:37 2026 +0100
@@ -139,7 +139,8 @@
def get_models(cls):
pool = Pool()
Model = pool.get('ir.model')
- return [(None, "")] + Model.get_name_items((ModelStorage, ModelView))
+ return [(None, ""),
+ *Model.get_name_items((ModelStorage,), (ModelView,))]
@classmethod
def from_webhook(cls, inbox, data, data_type):
diff -r ccc9209a41cc -r 1eca815d4df4 trytond/trytond/ir/model.py
--- a/trytond/trytond/ir/model.py Sat Oct 31 14:25:54 2026 +0100
+++ b/trytond/trytond/ir/model.py Wed Oct 28 15:14:37 2026 +0100
@@ -166,15 +166,18 @@
and model._on_change_notify_depends}
@classmethod
- def get_name_items(cls, classes=None):
+ def get_name_items(cls, classes=None, *other_classes):
"Return a list of couple mapping models to names"
pool = Pool()
- key = 'items', str(classes)
+ key = 'items', str(classes), str(other_classes)
items = cls._get_names_cache.get(key)
if items is None:
models = cls.search([])
items = ((m.name, m.string) for m in models)
+ all_classes = list(other_classes)
if classes:
+ all_classes.append(classes)
+ if all_classes:
def pool_get(model):
# During update existing model may not yet be in the pool
try:
@@ -183,17 +186,17 @@
return object
items = (
(m, n) for m, n in items
- if issubclass(pool_get(m), classes))
+ if all(issubclass(pool_get(m), k) for k in all_classes))
items = cls._get_names_cache.set(key, list(items))
return list(items)
@classmethod
- def get_names(cls, classes=None):
+ def get_names(cls, classes=None, *other_classes):
"Return a dictionary mapping models to names"
- key = 'dict', str(classes)
+ key = 'dict', str(classes), str(other_classes)
dict_ = cls._get_names_cache.get(key)
if dict_ is None:
- dict_ = dict(cls.get_name_items(classes=classes))
+ dict_ = dict(cls.get_name_items(classes=classes, *other_classes))
dict_ = cls._get_names_cache.set(key, dict_)
return dict_
diff -r ccc9209a41cc -r 1eca815d4df4 trytond/trytond/ir/resource.py
--- a/trytond/trytond/ir/resource.py Sat Oct 31 14:25:54 2026 +0100
+++ b/trytond/trytond/ir/resource.py Wed Oct 28 15:14:37 2026 +0100
@@ -49,7 +49,7 @@
pool = Pool()
Model = pool.get('ir.model')
ModelAccess = pool.get('ir.model.access')
- models = Model.get_name_items((ModelStorage, ModelView))
+ models = Model.get_name_items((ModelStorage,), (ModelView,))
if Transaction().check_access:
access = ModelAccess.get_access([m for m, _ in models])
models = [(m, n) for m, n in models if access[m]['read']]
diff -r ccc9209a41cc -r 1eca815d4df4 trytond/trytond/tests/resource.py
--- a/trytond/trytond/tests/resource.py Sat Oct 31 14:25:54 2026 +0100
+++ b/trytond/trytond/tests/resource.py Wed Oct 28 15:14:37 2026 +0100
@@ -1,11 +1,11 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.ir.note import NoteCopyMixin
-from trytond.model import ModelSQL
+from trytond.model import ModelSQL, ModelView
from trytond.pool import Pool
-class TestResource(ModelSQL, NoteCopyMixin):
+class TestResource(ModelSQL, ModelView, NoteCopyMixin):
__name__ = 'test.resource'
@classmethod
@@ -13,7 +13,7 @@
return {'test.resource.other'}
-class TestResourceOther(ModelSQL):
+class TestResourceOther(ModelSQL, ModelView):
__name__ = 'test.resource.other'