Cédric Krier pushed to branch branch/default at Tryton / Tryton


Commits:
33f058b9 by Cédric Krier at 2022-12-30T14:02:36+01:00
Do not join with target table of Many2One for only id clause

Also since 1b31be06c525 there is no need to add an active clause as the active
test is disabled by the decorator.

Closes #11841
- - - - -


2 changed files:

- trytond/trytond/model/fields/many2one.py
- trytond/trytond/tests/test_field_many2one.py


Changes:

=====================================
trytond/trytond/model/fields/many2one.py
=====================================
@@ -258,9 +258,7 @@
         else:
             _, target_name = name.split('.', 1)
         target_domain = [(target_name,) + tuple(domain[1:])]
-        if 'active' in Target._fields:
-            target_domain.append(('active', 'in', [True, False]))
         if self.target_search == 'subquery':
             query = Target.search(target_domain, order=[], query=True)
             return column.in_(query)
         else:
@@ -263,9 +261,7 @@
         if self.target_search == 'subquery':
             query = Target.search(target_domain, order=[], query=True)
             return column.in_(query)
         else:
-            target_tables = self._get_target_tables(tables)
-            target_table, _ = target_tables[None]
             rule_domain = Rule.domain_get(Target.__name__, mode='read')
             if rule_domain:
                 target_domain = [target_domain, rule_domain]
@@ -269,6 +265,12 @@
             rule_domain = Rule.domain_get(Target.__name__, mode='read')
             if rule_domain:
                 target_domain = [target_domain, rule_domain]
+            elif target_name == 'id':
+                # No need to join with the target table
+                return super().convert_domain(
+                    (self.name, operator, value), tables, Model)
+            target_tables = self._get_target_tables(tables)
+            target_table, _ = target_tables[None]
             _, expression = Target.search_domain(
                 target_domain, tables=target_tables)
             return expression


=====================================
trytond/trytond/tests/test_field_many2one.py
=====================================
@@ -144,6 +144,19 @@
         self.assertListEqual(values, [2, 3, 5])
 
     @with_transaction()
+    def test_search_id(self):
+        "Test search on many2one id"
+        pool = Pool()
+        Target = pool.get('test.many2one_target')
+        Many2One = pool.get('test.many2one')
+
+        target, = Target.create([{}])
+        record, = Many2One.create([{'many2one': target.id}])
+
+        result = Many2One.search([('many2one', '=', target.id)])
+        self.assertListEqual(result, [record])
+
+    @with_transaction()
     def _test_search_join(self, target_search):
         pool = Pool()
         Target = pool.get('test.many2one_target')



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/33f058b95151e31fd0d1a3303e1cb9c3c86e58c8

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/33f058b95151e31fd0d1a3303e1cb9c3c86e58c8
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to