From e5f0688da7432bd6abb18643c9049e098779dda3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 24 Mar 2025 23:32:36 +0100 Subject: [PATCH] Store target of field as relation For Many2Many it replaces the relation model by the target which is what is expected by usage in many places like the domain for email models. Closes #13756 --- trytond/CHANGELOG | 1 + trytond/trytond/ir/model.py | 13 ++++--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index ef45b607c1..eb25b70284 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Store target of field as relation * Remove support for Python 3.8 * Add support for Python 3.13 * Add on_write to ModelStorage diff --git a/trytond/trytond/ir/model.py b/trytond/trytond/ir/model.py index c50c83974c..da21cb66f8 100644 --- a/trytond/trytond/ir/model.py +++ b/trytond/trytond/ir/model.py @@ -344,7 +344,6 @@ class ModelField( @classmethod def register(cls, model, module_name, model_id): - pool = Pool() cursor = Transaction().connection.cursor() ir_model_field = cls.__table__() @@ -363,17 +362,13 @@ class ModelField( model_fields = {f['name']: f for f in cursor_dict(cursor)} for field_name, field in model._fields.items(): - if hasattr(field, 'model_name'): - relation = field.model_name - elif hasattr(field, 'relation_name'): - relation = field.relation_name + if hasattr(field, 'get_target'): + Relation = field.get_target() + relation = Relation.__name__ + Model.register(Relation, module_name) else: relation = None - if relation: - Relation = pool.get(relation) - Model.register(Relation, module_name) - access = field_name in model.__access__ if field_name not in model_fields: