details:   https://code.tryton.org/tryton/commit/a1579c166454
branch:    7.4
user:      Nicolas Évrard <[email protected]>
date:      Sat Dec 13 14:57:52 2025 +0100
description:
        Use the target id to compute the filter clause of a O2M field compared 
to None

        Closes #14373
        (grafted from 6b5e31b69ae62dabb2ad3253d9018945a467dbf1)
diffstat:

 trytond/trytond/model/fields/one2many.py     |   2 +-
 trytond/trytond/tests/test_field_one2many.py |  15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletions(-)

diffs (37 lines):

diff -r 5f9acc7045a8 -r a1579c166454 trytond/trytond/model/fields/one2many.py
--- a/trytond/trytond/model/fields/one2many.py  Sat Dec 13 14:33:42 2025 +0100
+++ b/trytond/trytond/model/fields/one2many.py  Sat Dec 13 14:57:52 2025 +0100
@@ -358,7 +358,7 @@
                     if self.filter:
                         query = Target.search(
                             self.filter, order=[], query=True)
-                        where &= origin.in_(query)
+                        where &= target.id.in_(query)
                     query = target.select(origin, where=where)
                     expression = ~table.id.in_(query)
                 else:
diff -r 5f9acc7045a8 -r a1579c166454 
trytond/trytond/tests/test_field_one2many.py
--- a/trytond/trytond/tests/test_field_one2many.py      Sat Dec 13 14:33:42 
2025 +0100
+++ b/trytond/trytond/tests/test_field_one2many.py      Sat Dec 13 14:57:52 
2025 +0100
@@ -611,6 +611,21 @@
         self.assertEqual(filtered_target.value, 3)
 
     @with_transaction()
+    def test_search_equals_filter(self):
+        "Test search one2many equals with filter"
+        One2Many = Pool().get('test.one2many_filter')
+        one2many, = One2Many.create([{
+                    'targets': [('create', [{'value': 3}])],
+                    }])
+
+        one2manys = One2Many.search([('targets', '=', None)])
+        one2manys_filtered = One2Many.search(
+            [('filtered_targets', '=', None)])
+
+        self.assertListEqual(one2manys, [])
+        self.assertListEqual(one2manys_filtered, [])
+
+    @with_transaction()
     def test_search_non_equals_filter(self):
         "Test search one2many non equals with filter"
         One2Many = Pool().get('test.one2many_filter')

Reply via email to