changeset 47a7d5c83171 in modules/account:6.4
details: https://hg.tryton.org/modules/account?cmd=changeset&node=47a7d5c83171
description:
        Invert SQL expression of domain_active

        When the value is False or the operator is negative, the range 
expression must
        be inverted.

        issue11492
        review419171003
        (grafted from 4d1fcd8640368282ec34d1359502408f5cd29f1f)
diffstat:

 common.py                         |  31 +++++++++++++++----------------
 tests/scenario_account_active.rst |  13 +++++++++++++
 2 files changed, 28 insertions(+), 16 deletions(-)

diffs (67 lines):

diff -r c19b40cd7ca6 -r 47a7d5c83171 common.py
--- a/common.py Mon May 02 16:48:47 2022 +0200
+++ b/common.py Tue May 31 23:46:14 2022 +0200
@@ -121,25 +121,24 @@
         table, _ = tables[None]
         _, operator, value = domain
 
-        if operator in {'=', '!='}:
-            if (operator == '=') == value:
-                operator = 'in'
-            else:
-                operator = 'not in'
-        elif operator in {'in', 'not in'}:
-            if True in value and False not in value:
-                operator = 'in'
-            elif False in value and True not in value:
-                operator = 'not in'
-            else:
-                return Literal(True)
-        else:
-            return Literal(True)
-
         from_date, to_date = cls._active_dates()
         start_date = Coalesce(table.start_date, datetime.date.min)
         end_date = Coalesce(table.end_date, datetime.date.max)
 
-        return (((start_date <= to_date) & (end_date >= to_date))
+        expression = (((start_date <= to_date) & (end_date >= to_date))
             | ((start_date <= from_date) & (end_date >= from_date))
             | ((start_date >= from_date) & (end_date <= to_date)))
+
+        if operator in {'=', '!='}:
+            if (operator == '=') != value:
+                expression = ~expression
+        elif operator in {'in', 'not in'}:
+            if True in value and False not in value:
+                pass
+            elif False in value and True not in value:
+                expression = ~expression
+            else:
+                expression = Literal(True)
+        else:
+            expression = Literal(True)
+        return expression
diff -r c19b40cd7ca6 -r 47a7d5c83171 tests/scenario_account_active.rst
--- a/tests/scenario_account_active.rst Mon May 02 16:48:47 2022 +0200
+++ b/tests/scenario_account_active.rst Tue May 31 23:46:14 2022 +0200
@@ -41,6 +41,19 @@
     True
     >>> len(Account.find([('id', '=', cash.id)]))
     1
+    >>> len(Account.find([('id', '=', cash.id), ('active', '=', True)]))
+    1
+    >>> len(Account.find([('id', '=', cash.id), ('active', 'in', [True])]))
+    1
+    >>> len(Account.find([('id', '=', cash.id), ('active', 'in', [True, 
False])]))
+    1
+
+Check negative search::
+
+    >>> len(Account.find([('id', '=', cash.id), ('active', '=', False)]))
+    0
+    >>> len(Account.find([('id', '=', cash.id), ('active', 'in', [False])]))
+    0
 
 Check active with a start date::
 

Reply via email to