changeset 4d1fcd864036 in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset&node=4d1fcd864036
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
diffstat:
common.py | 31 +++++++++++++++----------------
tests/scenario_account_active.rst | 13 +++++++++++++
2 files changed, 28 insertions(+), 16 deletions(-)
diffs (67 lines):
diff -r e7c83ca86a89 -r 4d1fcd864036 common.py
--- a/common.py Tue May 31 09:39:25 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 e7c83ca86a89 -r 4d1fcd864036 tests/scenario_account_active.rst
--- a/tests/scenario_account_active.rst Tue May 31 09:39:25 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::