changeset dda2f05a83cd in modules/marketing_email:default
details: 
https://hg.tryton.org/modules/marketing_email?cmd=changeset&node=dda2f05a83cd
description:
        Use declarative index definition for ModelSQL

        issue5757
        review361251002
diffstat:

 marketing.py |  21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)

diffs (50 lines):

diff -r 1e7bdc58c4a8 -r dda2f05a83cd marketing.py
--- a/marketing.py      Mon May 09 23:47:10 2022 +0200
+++ b/marketing.py      Tue Oct 11 00:44:49 2022 +0200
@@ -25,7 +25,7 @@
 from trytond.i18n import gettext
 from trytond.ir.session import token_hex
 from trytond.model import (
-    DeactivableMixin, ModelSQL, ModelView, Unique, Workflow, fields)
+    DeactivableMixin, Index, ModelSQL, ModelView, Unique, Workflow, fields)
 from trytond.pool import Pool
 from trytond.pyson import Eval
 from trytond.report import Report, get_email
@@ -90,14 +90,10 @@
             ('email_list_unique', Unique(t, t.email, t.list_),
                 'marketing.msg_email_list_unique'),
             ]
-
-    @classmethod
-    def __register__(cls, module_name):
-        super().__register__(module_name)
-
-        table_h = cls.__table_handler__(module_name)
-        table_h.index_action(['email', 'list_'], action='add')
-        table_h.index_action(['list_', 'active'], action='add')
+        cls._sql_indexes.add(Index(
+                t,
+                (t.list_, Index.Equality()),
+                (t.email, Index.Equality())))
 
     @classmethod
     def default_email_token(cls, nbytes=None):
@@ -357,12 +353,17 @@
             ('draft', "Draft"),
             ('sending', "Sending"),
             ('sent', "Sent"),
-            ], "State", readonly=True, select=True, sort=False)
+            ], "State", readonly=True, sort=False)
     del _states
 
     @classmethod
     def __setup__(cls):
         super().__setup__()
+        t = cls.__table__()
+        cls._sql_indexes.add(
+            Index(
+                t, (t.state, Index.Equality()),
+                where=t.state.in_(['draft', 'sending'])))
         cls._transitions |= set([
                 ('draft', 'sending'),
                 ('sending', 'sent'),

Reply via email to