changeset 6fa943bab6bf in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset&node=6fa943bab6bf
description:
        Search active period with SQL clause instead of a subquery

        issue10344
        review351841002
diffstat:

 common.py |  16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)

diffs (52 lines):

diff -r 05a3dd4ca183 -r 6fa943bab6bf common.py
--- a/common.py Sun May 16 17:58:08 2021 +0200
+++ b/common.py Wed May 19 15:28:21 2021 +0200
@@ -2,6 +2,7 @@
 # this repository contains the full copyright notices and license terms.
 import datetime
 
+from sql import Literal
 from sql.conditionals import Coalesce
 
 from trytond.model import Model, fields
@@ -66,8 +67,7 @@
 
 class ActivePeriodMixin(PeriodMixin):
 
-    active = fields.Function(
-        fields.Boolean("Active"), 'get_active', searcher='search_active')
+    active = fields.Function(fields.Boolean("Active"), 'get_active')
 
     @classmethod
     def _active_dates(cls):
@@ -119,8 +119,8 @@
             or (from_date <= start_date and end_date <= to_date))
 
     @classmethod
-    def search_active(cls, name, domain):
-        table = cls.__table__()
+    def domain_active(cls, domain, tables):
+        table, _ = tables[None]
         _, operator, value = domain
 
         if operator in {'=', '!='}:
@@ -134,16 +134,14 @@
             elif False in value and True not in value:
                 operator = 'not in'
             else:
-                return []
+                return Literal(True)
         else:
-            return []
+            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)
 
-        query = table.select(table.id,
-            where=((start_date <= to_date) & (end_date >= to_date))
+        return (((start_date <= to_date) & (end_date >= to_date))
             | ((start_date <= from_date) & (end_date >= from_date))
             | ((start_date >= from_date) & (end_date <= to_date)))
-        return [('id', operator, query)]

Reply via email to