changeset 3618ad48af99 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=3618ad48af99
description:
        Do not return None when evaluating domain with in operator

        When the operator is 'in' and the value contains None, 
Field._domain_add_null
        adds an equal operator against NULL. So this must be managed like the 
'='
        operator.

        issue9906
        review332201005
diffstat:

 trytond/tests/test_tools.py       |  10 ++++++++++
 trytond/tools/domain_inversion.py |   5 ++++-
 2 files changed, 14 insertions(+), 1 deletions(-)

diffs (42 lines):

diff -r e2fc3f441cb3 -r 3618ad48af99 trytond/tests/test_tools.py
--- a/trytond/tests/test_tools.py       Thu Mar 18 23:03:55 2021 +0100
+++ b/trytond/tests/test_tools.py       Sat Mar 20 12:33:09 2021 +0100
@@ -540,6 +540,11 @@
         self.assertTrue(eval_domain(domain, {'x': [3]}))
         self.assertTrue(eval_domain(domain, {'x': [3, 4]}))
         self.assertFalse(eval_domain(domain, {'x': [1, 2]}))
+        self.assertFalse(eval_domain(domain, {'x': None}))
+
+        domain = [['x', 'in', [1, None]]]
+        self.assertTrue(eval_domain(domain, {'x': None}))
+        self.assertFalse(eval_domain(domain, {'x': 2}))
 
         domain = [['x', 'not in', [3, 5]]]
         self.assertFalse(eval_domain(domain, {'x': 3}))
@@ -547,6 +552,11 @@
         self.assertFalse(eval_domain(domain, {'x': [3]}))
         self.assertFalse(eval_domain(domain, {'x': [3, 4]}))
         self.assertTrue(eval_domain(domain, {'x': [1, 2]}))
+        self.assertFalse(eval_domain(domain, {'x': None}))
+
+        domain = [['x', 'not in', [1, None]]]
+        self.assertFalse(eval_domain(domain, {'x': None}))
+        self.assertTrue(eval_domain(domain, {'x': 2}))
 
         domain = [['x', 'like', 'abc']]
         self.assertTrue(eval_domain(domain, {'x': 'abc'}))
diff -r e2fc3f441cb3 -r 3618ad48af99 trytond/tools/domain_inversion.py
--- a/trytond/tools/domain_inversion.py Thu Mar 18 23:03:55 2021 +0100
+++ b/trytond/tools/domain_inversion.py Sat Mar 20 12:33:09 2021 +0100
@@ -96,7 +96,10 @@
         return bool(context.get(field.split('.')[0]))
     context_field = context.get(field)
     if (operand not in {'=', '!='}
-            and (context_field is None or value is None)):
+            and (context_field is None or value is None)
+            and not (operand in {'in', 'not in'}
+                and context_field is None
+                and (isinstance(value, (list, tuple)) and None in value))):
         return
     if isinstance(context_field, datetime.date) and not value:
         if isinstance(context_field, datetime.datetime):

Reply via email to