Use the target id to compute the filter clause of a O2M field compared to None

Closes #14373
This commit is contained in:
Nicolas Évrard
2025-12-13 14:57:52 +01:00
parent a23df14c83
commit 64424d1a90
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -358,7 +358,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:
@@ -611,6 +611,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"