From 81e7cf7c213a0d599ae21042f777459205c337de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 11 Oct 2022 00:44:50 +0200 Subject: [PATCH] Use declarative index definition for ModelSQL issue5757 review361251002 --- stock.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/stock.py b/stock.py index c71c7242bf..7d99098096 100644 --- a/stock.py +++ b/stock.py @@ -12,7 +12,7 @@ from sql.operators import Concat from trytond import backend from trytond.i18n import gettext -from trytond.model import ModelSQL, ModelView, Workflow, fields +from trytond.model import Index, ModelSQL, ModelView, Workflow, fields from trytond.model.exceptions import AccessError from trytond.modules.product import round_price from trytond.modules.purchase.stock import process_purchase @@ -107,7 +107,8 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): states={ 'readonly': Eval('state') != 'draft', }) - reference = fields.Char('Reference', select=1, + reference = fields.Char( + "Reference", states={ 'readonly': Eval('state') != 'draft', }) @@ -172,7 +173,7 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): }, depends={'customer'}) number = fields.Char( - "Number", select=True, readonly=True, + "Number", readonly=True, help="The main identifier for the shipment.") state = fields.Selection([ ('draft', 'Draft'), @@ -262,7 +263,16 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): @classmethod def __setup__(cls): + cls.number.search_unaccented = False + cls.reference.search_unaccented = False super(ShipmentDrop, cls).__setup__() + t = cls.__table__() + cls._sql_indexes.update({ + Index(t, (t.reference, Index.Similarity())), + Index( + t, (t.state, Index.Equality()), + where=t.state.in_(['draft', 'waiting', 'shipped'])), + }) cls._order = [ ('effective_date', 'ASC NULLS LAST'), ('id', 'DESC'),