diff --git a/trytond/trytond/model/fields/boolean.py b/trytond/trytond/model/fields/boolean.py index bcef0f88a6..50ad5fa36f 100644 --- a/trytond/trytond/model/fields/boolean.py +++ b/trytond/trytond/model/fields/boolean.py @@ -1,6 +1,8 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from sql import Null + from .field import Field @@ -33,4 +35,6 @@ class Boolean(Field): expression |= (column == conv[value]) else: expression &= (column != conv[value]) + elif value and operator == '!=': + expression |= (column == Null) return expression diff --git a/trytond/trytond/tests/test_field_boolean.py b/trytond/trytond/tests/test_field_boolean.py index d1f66af499..a345a6b69b 100644 --- a/trytond/trytond/tests/test_field_boolean.py +++ b/trytond/trytond/tests/test_field_boolean.py @@ -229,6 +229,32 @@ class FieldBooleanTestCase(TestCase): ]) self.assertListEqual(booleans, []) + @with_transaction() + def test_search_equals_true_with_none(self): + "Test search boolean equals True with None" + Boolean = Pool().get('test.boolean') + boolean, = Boolean.create([{ + 'boolean': None, + }]) + + booleans = Boolean.search([ + ('boolean', '=', True), + ]) + self.assertListEqual(booleans, []) + + @with_transaction() + def test_search_non_equals_true_with_none(self): + "Test search boolean non equals True with None" + Boolean = Pool().get('test.boolean') + boolean, = Boolean.create([{ + 'boolean': None, + }]) + + booleans = Boolean.search([ + ('boolean', '!=', True), + ]) + self.assertListEqual(booleans, [boolean]) + @with_transaction() def test_write_false(self): "Test write boolean False"