From eac648d26ab3d9c4141fd92a6e81c67667000ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 11 Oct 2022 00:44:49 +0200 Subject: [PATCH] Use declarative index definition for ModelSQL issue5757 review361251002 --- marketing_automation.py | 13 ++++++++++++- party.py | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/marketing_automation.py b/marketing_automation.py index 097ef5815f..8eafdcb8b4 100644 --- a/marketing_automation.py +++ b/marketing_automation.py @@ -26,7 +26,8 @@ from sql.functions import Position, Substring from trytond.config import config from trytond.i18n import gettext from trytond.model import ( - EvalEnvironment, ModelSQL, ModelView, Unique, Workflow, dualmethod, fields) + EvalEnvironment, Index, ModelSQL, ModelView, Unique, Workflow, dualmethod, + fields) from trytond.pool import Pool from trytond.pyson import Eval, If, PYSONDecoder from trytond.report import Report @@ -85,6 +86,11 @@ class Scenario(Workflow, ModelSQL, ModelView): @classmethod def __setup__(cls): super().__setup__() + t = cls.__table__() + cls._sql_indexes.add( + Index( + t, (t.state, Index.Equality()), + where=t.state.in_(['draft', 'running']))) cls._transitions |= set(( ('draft', 'running'), ('running', 'stopped'), @@ -767,6 +773,11 @@ class RecordActivity(Workflow, ModelSQL, ModelView): ('activity_record_unique', Unique(t, t.activity, t.record), 'marketing_automation.msg_activity_record_unique'), ] + cls._sql_indexes.add( + Index( + t, + (t.state, Index.Equality()), + where=t.state.in_(['waiting']))) cls._transitions |= set(( ('waiting', 'done'), ('waiting', 'cancelled'), diff --git a/party.py b/party.py index 0d8d3cfa21..b6ed5d6995 100644 --- a/party.py +++ b/party.py @@ -42,7 +42,7 @@ class PartyUnsubscribedScenario(ModelSQL): __name__ = 'party.party-unsubscribed-marketing.automation.scenario' party = fields.Many2One( - 'party.party', "Party", required=True, select=True, ondelete='CASCADE') + 'party.party', "Party", required=True, ondelete='CASCADE') scenario = fields.Many2One( 'marketing.automation.scenario', "Scenario", required=True, ondelete='CASCADE')