details:   https://code.tryton.org/tryton/commit/dc82735fc39d
branch:    6.0
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 bd2a039ec306 -r dc82735fc39d trytond/trytond/model/fields/one2many.py
--- a/trytond/trytond/model/fields/one2many.py  Sun Dec 14 20:12:58 2025 +0100
+++ b/trytond/trytond/model/fields/one2many.py  Sat Dec 13 14:57:52 2025 +0100
@@ -318,7 +318,7 @@
                     where &= origin_where
                 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)
                 if operator == '!=':
diff -r bd2a039ec306 -r dc82735fc39d 
trytond/trytond/tests/test_field_one2many.py
--- a/trytond/trytond/tests/test_field_one2many.py      Sun Dec 14 20:12:58 
2025 +0100
+++ b/trytond/trytond/tests/test_field_one2many.py      Sat Dec 13 14:57:52 
2025 +0100
@@ -550,6 +550,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