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

        issue5757
        review361251002
diffstat:

 work.py |  23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diffs (58 lines):

diff -r 9119aa23dfe9 -r a54b2e980d83 work.py
--- a/work.py   Thu Jun 16 14:32:44 2022 +0200
+++ b/work.py   Tue Oct 11 00:44:50 2022 +0200
@@ -8,7 +8,8 @@
 from trytond.cache import Cache
 from trytond.i18n import gettext
 from trytond.model import (
-    DeactivableMixin, ModelSQL, ModelView, fields, sequence_ordered, tree)
+    DeactivableMixin, Index, ModelSQL, ModelView, fields, sequence_ordered,
+    tree)
 from trytond.pool import Pool
 from trytond.pyson import Bool, Eval, If, PYSONEncoder
 from trytond.tools import grouped_slice, reduce_ids
@@ -121,14 +122,13 @@
 class Work(sequence_ordered(), tree(separator='\\'), ModelSQL, ModelView):
     'Work Effort'
     __name__ = 'project.work'
-    name = fields.Char('Name', required=True, select=True)
+    name = fields.Char("Name", required=True)
     type = fields.Selection([
             ('project', 'Project'),
             ('task', 'Task')
             ],
-        'Type', required=True, select=True)
-    company = fields.Many2One('company.company', 'Company', required=True,
-        select=True)
+        "Type", required=True)
+    company = fields.Many2One('company.company', "Company", required=True)
     party = fields.Many2One('party.party', 'Party',
         states={
             'invisible': Eval('type') != 'project',
@@ -190,15 +190,24 @@
         domain=[
             ('company', '=', Eval('company', -1)),
             ])
-    path = fields.Char("Path", select=True)
+    path = fields.Char("Path")
     children = fields.One2Many('project.work', 'parent', 'Children',
         domain=[
             ('company', '=', Eval('company', -1)),
             ])
     status = fields.Many2One(
-        'project.work.status', "Status", required=True, select=True,
+        'project.work.status', "Status", required=True,
         domain=[If(Bool(Eval('type')), ('types', 'in', Eval('type')), ())])
 
+    @classmethod
+    def __setup__(cls):
+        cls.path.search_unaccented = False
+        super().__setup__()
+        t = cls.__table__()
+        cls._sql_indexes.update({
+                Index(t, (t.path, Index.Similarity(begin=True))),
+                })
+
     @staticmethod
     def default_type():
         return 'task'

Reply via email to