diff --git a/trytond/trytond/model/fields/multiselection.py b/trytond/trytond/model/fields/multiselection.py index c34b21de53..8eeeff1eac 100644 --- a/trytond/trytond/model/fields/multiselection.py +++ b/trytond/trytond/model/fields/multiselection.py @@ -91,7 +91,9 @@ class MultiSelection(SelectionMixin, Field): database = Transaction().database table, _ = tables[None] raw_column = self.sql_column(table) - if isinstance(value, str): + if value is None: + expression = Literal(False) + elif isinstance(value, str): try: expression = database.json_key_exists(raw_column, value) except NotImplementedError: diff --git a/trytond/trytond/tests/test_field_multiselection.py b/trytond/trytond/tests/test_field_multiselection.py index 881d59ecda..8f09498fa6 100644 --- a/trytond/trytond/tests/test_field_multiselection.py +++ b/trytond/trytond/tests/test_field_multiselection.py @@ -231,6 +231,32 @@ class FieldMultiSelectionTestCase(unittest.TestCase): self.assertEqual(selections, [selection]) + @with_transaction() + def test_search_in_none(self): + "Test search selection in None" + Selection = Pool().get('test.multi_selection') + selection, = Selection.create([{ + 'selects': ['foo', 'bar'], + }]) + + result = Selection.search([ + ('selects', 'in', None), + ]) + self.assertEqual(result, []) + + @with_transaction() + def test_search_not_in_none(self): + "Test search selection not in None" + Selection = Pool().get('test.multi_selection') + selection, = Selection.create([{ + 'selects': ['foo', 'bar'], + }]) + + result = Selection.search([ + ('selects', 'not in', None), + ]) + self.assertEqual(result, [selection]) + @with_transaction() def test_search_in_string(self): "Test search selection in string"