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

        issue5757
        review361251002
diffstat:

 __init__.py          |   4 +++-
 address.py           |   5 +++--
 category.py          |   2 +-
 contact_mechanism.py |  10 ++++++----
 country.py           |  21 +++++++++++++++++++++
 party.py             |  30 ++++++++++++++++++------------
 6 files changed, 52 insertions(+), 20 deletions(-)

diffs (193 lines):

diff -r 51c602f3a120 -r c0d49f1c6391 __init__.py
--- a/__init__.py       Sat Oct 01 15:21:17 2022 +0200
+++ b/__init__.py       Tue Oct 11 00:44:49 2022 +0200
@@ -3,11 +3,13 @@
 
 from trytond.pool import Pool
 
-from . import address, category, configuration, contact_mechanism, ir, party
+from . import (
+    address, category, configuration, contact_mechanism, country, ir, party)
 
 
 def register():
     Pool.register(
+        country.PostalCode,
         category.Category,
         party.Party,
         party.PartyLang,
diff -r 51c602f3a120 -r c0d49f1c6391 address.py
--- a/address.py        Sat Oct 01 15:21:17 2022 +0200
+++ b/address.py        Tue Oct 11 00:44:49 2022 +0200
@@ -28,8 +28,9 @@
         ModelSQL, ModelView):
     "Address"
     __name__ = 'party.address'
-    party = fields.Many2One('party.party', 'Party', required=True,
-        ondelete='CASCADE', select=True, states={
+    party = fields.Many2One(
+        'party.party', "Party", required=True, ondelete='CASCADE',
+        states={
             'readonly': Eval('id', 0) > 0,
             })
     party_name = fields.Char(
diff -r 51c602f3a120 -r c0d49f1c6391 category.py
--- a/category.py       Sat Oct 01 15:21:17 2022 +0200
+++ b/category.py       Tue Oct 11 00:44:49 2022 +0200
@@ -14,7 +14,7 @@
         "Name", required=True, translate=True,
         help="The main identifier of the category.")
     parent = fields.Many2One(
-        'party.category', "Parent", select=True,
+        'party.category', "Parent",
         help="Add the category below the parent.")
     childs = fields.One2Many(
         'party.category', 'parent', "Children",
diff -r 51c602f3a120 -r c0d49f1c6391 contact_mechanism.py
--- a/contact_mechanism.py      Sat Oct 01 15:21:17 2022 +0200
+++ b/contact_mechanism.py      Tue Oct 11 00:44:49 2022 +0200
@@ -71,7 +71,8 @@
     _rec_name = 'value'
 
     type = fields.Selection(_TYPES, "Type", required=True, sort=False)
-    value = fields.Char("Value", select=True,
+    value = fields.Char(
+        "Value",
         # Add all function fields to ensure to always fill them via on_change
         depends={
             'email', 'website', 'skype', 'sip', 'other_value',
@@ -80,9 +81,9 @@
     name = fields.Char("Name")
     comment = fields.Text("Comment")
     party = fields.Many2One(
-        'party.party', "Party", required=True, ondelete='CASCADE', select=True)
+        'party.party', "Party", required=True, ondelete='CASCADE')
     address = fields.Many2One(
-        'party.address', "Address", ondelete='CASCADE', select=True,
+        'party.address', "Address", ondelete='CASCADE',
         domain=[
             ('party', '=', Eval('party', -1)),
             ])
@@ -125,6 +126,7 @@
 
     @classmethod
     def __setup__(cls):
+        cls.value.search_unaccented = False
         super(ContactMechanism, cls).__setup__()
         cls._order.insert(0, ('party.distance', 'ASC NULLS LAST'))
         cls._order.insert(1, ('party', 'ASC'))
@@ -330,5 +332,5 @@
     __name__ = 'party.contact_mechanism.language'
     contact_mechanism = fields.Many2One(
         'party.contact_mechanism', "Contact Mechanism",
-        ondelete='CASCADE', select=True)
+        ondelete='CASCADE')
     language = fields.Many2One('ir.lang', "Language")
diff -r 51c602f3a120 -r c0d49f1c6391 country.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/country.py        Tue Oct 11 00:44:49 2022 +0200
@@ -0,0 +1,21 @@
+# This file is part of Tryton.  The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+
+from trytond.model import Index
+from trytond.pool import PoolMeta
+
+
+class PostalCode(metaclass=PoolMeta):
+    __name__ = 'country.postal_code'
+
+    @classmethod
+    def __setup__(cls):
+        super().__setup__()
+        t = cls.__table__()
+        cls._sql_indexes.update({
+                Index(
+                    t,
+                    (Index.Unaccent(t.city), Index.Similarity()),
+                    (t.country, Index.Equality()),
+                    (t.subdivision, Index.Equality())),
+                })
diff -r 51c602f3a120 -r c0d49f1c6391 party.py
--- a/party.py  Sat Oct 01 15:21:17 2022 +0200
+++ b/party.py  Tue Oct 11 00:44:49 2022 +0200
@@ -9,8 +9,8 @@
 from trytond import backend
 from trytond.i18n import gettext
 from trytond.model import (
-    DeactivableMixin, ModelSQL, ModelView, MultiValueMixin, Unique, ValueMixin,
-    fields, sequence_ordered)
+    DeactivableMixin, Index, ModelSQL, ModelView, MultiValueMixin, Unique,
+    ValueMixin, fields, sequence_ordered)
 from trytond.model.exceptions import AccessError
 from trytond.pool import Pool
 from trytond.pyson import Bool, Eval
@@ -35,9 +35,10 @@
         }
 
     name = fields.Char(
-        "Name", select=True, strip=False,
+        "Name", strip=False,
         help="The main identifier of the party.")
-    code = fields.Char('Code', required=True, select=True,
+    code = fields.Char(
+        "Code", required=True,
         states={
             'readonly': Eval('code_readonly', True),
             },
@@ -89,11 +90,16 @@
 
     @classmethod
     def __setup__(cls):
+        cls.code.search_unaccented = False
         super(Party, cls).__setup__()
         t = cls.__table__()
         cls._sql_constraints = [
             ('code_uniq', Unique(t, t.code), 'party.msg_party_code_unique')
             ]
+        cls._sql_indexes.update({
+                Index(t, (t.code, Index.Equality())),
+                Index(t, (t.code, Index.Similarity())),
+                })
         cls._order.insert(0, ('distance', 'ASC NULLS LAST'))
         cls._order.insert(1, ('name', 'ASC'))
         cls.active.states.update({
@@ -332,7 +338,7 @@
     "Party Lang"
     __name__ = 'party.party.lang'
     party = fields.Many2One(
-        'party.party', "Party", ondelete='CASCADE', select=True)
+        'party.party', "Party", ondelete='CASCADE')
     lang = fields.Many2One('ir.lang', "Language")
 
     @classmethod
@@ -370,10 +376,10 @@
     'Party - Category'
     __name__ = 'party.party-party.category'
     _table = 'party_category_rel'
-    party = fields.Many2One('party.party', 'Party', ondelete='CASCADE',
-            required=True, select=True)
-    category = fields.Many2One('party.category', 'Category',
-        ondelete='CASCADE', required=True, select=True)
+    party = fields.Many2One(
+        'party.party', "Party", ondelete='CASCADE', required=True)
+    category = fields.Many2One(
+        'party.category', "Category", ondelete='CASCADE', required=True)
 
 
 IDENTIFIER_TYPES = [
@@ -596,11 +602,11 @@
     'Party Identifier'
     __name__ = 'party.identifier'
     _rec_name = 'code'
-    party = fields.Many2One('party.party', 'Party', ondelete='CASCADE',
-        required=True, select=True,
+    party = fields.Many2One(
+        'party.party', "Party", ondelete='CASCADE', required=True,
         help="The party identified by this record.")
     address = fields.Many2One(
-        'party.address', "Address", ondelete='CASCADE', select=True,
+        'party.address', "Address", ondelete='CASCADE',
         states={
             'required': Eval('type_address', False),
             'invisible': ~Eval('type_address', True),

Reply via email to