From 78e755fac07a40fbc5c34b437493ce200083c119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Sat, 13 Dec 2025 14:57:52 +0100 Subject: [PATCH] Use the target id to compute the filter clause of a O2M field compared to None Closes #14373 (grafted from 6b5e31b69ae62dabb2ad3253d9018945a467dbf1) --HG-- branch : 7.0 --- trytond/trytond/model/fields/one2many.py | 2 +- trytond/trytond/tests/test_field_one2many.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/trytond/trytond/model/fields/one2many.py b/trytond/trytond/model/fields/one2many.py index 0cd7b65926..80ffc94453 100644 --- a/trytond/trytond/model/fields/one2many.py +++ b/trytond/trytond/model/fields/one2many.py @@ -350,7 +350,7 @@ class One2Many(Field): 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 --git a/trytond/trytond/tests/test_field_one2many.py b/trytond/trytond/tests/test_field_one2many.py index 9af33c25c3..65b1990a6f 100644 --- a/trytond/trytond/tests/test_field_one2many.py +++ b/trytond/trytond/tests/test_field_one2many.py @@ -610,6 +610,21 @@ class FieldOne2ManyTestCase( self.assertEqual(len(filtered.targets), 4) 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"