Support child_of/parent_of with None in the value list

This was a implicit behaviour before the changeset 6fefd00369c1.
As a lot of code rely on this behaviour, we make it explicit by adding a test
case.

issue7405
review36251002
This commit is contained in:
Cédric Krier committed 2018-05-03 11:57:10 +02:00
1 parent 4c1fe028c1
commit 4ed54e9bbc
2 files changed
+21 -3

No files matched your search

+2 -3
View File
@@ -116,7 +116,7 @@ class Many2One(Field):
cursor = Transaction().connection.cursor()
table, _ = tables[None]
name, operator, ids = domain
red_sql = reduce_ids(table.id, ids)
red_sql = reduce_ids(table.id, (i for i in ids if i is not None))
Target = self.get_target()
left = getattr(Target, self.left).sql_column(table)
right = getattr(Target, self.right).sql_column(table)
@@ -138,8 +138,7 @@ class Many2One(Field):
target = Target.__table__()
table, _ = tables[None]
name, operator, ids = domain
ids = set(ids) # Ensure it is a set for concatenation
red_sql = reduce_ids(target.id, ids)
red_sql = reduce_ids(target.id, (i for i in ids if i is not None))
if operator.endswith('child_of'):
tree = With('id', recursive=True)
+19
View File
@@ -320,6 +320,25 @@ class FieldMany2OneTestCase(unittest.TestCase):
"Test search many2one mptt not child of empty"
self._test_search_not_child_of_empty('test.many2one_mptt')
@with_transaction()
def _test_search_child_of_none(self, model_name):
Many2One = Pool().get(model_name)
self.create_tree(Many2One)
result = Many2One.search([
('many2one', 'child_of', [None]),
])
self.assertListEqual(result, [])
def test_search_tree_child_of_none(self):
"Test search many2one tree child of None"
self._test_search_child_of_none('test.many2one_tree')
def test_search_mptt_child_of_none(self):
"Test search many2one mptt child of None"
self._test_search_child_of_none('test.many2one_mptt')
@with_transaction()
def _test_search_parent_of_root1(self, model_name):
Many2One = Pool().get(model_name)