From 2d8cc458fda361ffa74fdc87d0db2dfa5a3da091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 10 Aug 2023 13:55:00 +0200 Subject: [PATCH] Convert element joined domains into domain when searching for OR-ed domain The content of joined domains can be a single clause, so it must be converted into a domain before calling search_domain. Closes #12460 --- trytond/trytond/model/modelsql.py | 1 + trytond/trytond/tests/test_modelsql.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/trytond/trytond/model/modelsql.py b/trytond/trytond/model/modelsql.py index 59f94b5ba8..3a7bba97ed 100644 --- a/trytond/trytond/model/modelsql.py +++ b/trytond/trytond/model/modelsql.py @@ -1655,6 +1655,7 @@ class ModelSQL(ModelStorage): if joined_domains is not None: union_tables = [] for sub_domain in joined_domains: + sub_domain = [sub_domain] # it may be a clause tables, expression = cls.search_domain(sub_domain) if rule_domain: tables, domain_exp = cls.search_domain( diff --git a/trytond/trytond/tests/test_modelsql.py b/trytond/trytond/tests/test_modelsql.py index 0bfc680c52..825f5aa3c5 100644 --- a/trytond/trytond/tests/test_modelsql.py +++ b/trytond/trytond/tests/test_modelsql.py @@ -823,6 +823,26 @@ class ModelSQLTestCase(unittest.TestCase): self.assertIn('UNION', str(Model.search(domain, query=True))) self.assertNotIn('UNION', str(query_without_split)) + @with_transaction() + def test_search_or_to_union_with_in_clause(self): + "Test searching for 'OR'-ed domain with in clause" + pool = Pool() + Model = pool.get('test.modelsql.search.or2union') + + record, = Model.create([{ + 'name': "Foo", + 'targets': [('create', [{ + 'name': "Bar", + }]), + ], + }]) + + domain = ['OR', + ('name', '=', 'Bar'), + ('targets.id', 'in', [t.id for t in record.targets]), + ] + self.assertEqual(Model.search(domain), [record]) + @with_transaction() def test_search_or_to_union_order_eager_field(self): """