From bfd8ecdc38914b6d30d764a4198bd62c2ee85ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 6 May 2026 09:23:35 +0200 Subject: [PATCH] Make search on boolean non equals to True is the same as different of False Closes #14815 (grafted from 7ac4b470f9e36f846b28d4c12e5e121e204d4aa1) --HG-- branch : 8.0 --- trytond/trytond/model/fields/boolean.py | 4 ++++ trytond/trytond/tests/test_field_boolean.py | 26 +++++++++++++++++++++ 2 files changed, 30 insertions(+) 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"