changeset 5c89b1563670 in modules/analytic_account:default
details:
https://hg.tryton.org/modules/analytic_account?cmd=changeset&node=5c89b1563670
description:
Use declarative index definition for ModelSQL
issue5757
review361251002
diffstat:
account.py | 21 ++++++++++++++-------
line.py | 13 +++++++++----
2 files changed, 23 insertions(+), 11 deletions(-)
diffs (125 lines):
diff -r ab59016bfe86 -r 5c89b1563670 account.py
--- a/account.py Fri Sep 16 23:37:38 2022 +0200
+++ b/account.py Tue Oct 11 00:44:49 2022 +0200
@@ -10,7 +10,7 @@
from trytond import backend
from trytond.i18n import gettext
from trytond.model import (
- DeactivableMixin, ModelSQL, ModelView, Unique, fields, tree)
+ DeactivableMixin, Index, ModelSQL, ModelView, Unique, fields, tree)
from trytond.modules.currency.fields import Monetary
from trytond.pool import Pool
from trytond.pyson import Eval, If, PYSONDecoder, PYSONEncoder
@@ -25,8 +25,8 @@
ModelSQL, ModelView):
'Analytic Account'
__name__ = 'analytic_account.account'
- name = fields.Char('Name', required=True, translate=True, select=True)
- code = fields.Char('Code', select=True)
+ name = fields.Char("Name", required=True, translate=True)
+ code = fields.Char("Code")
company = fields.Many2One('company.company', 'Company', required=True)
currency = fields.Function(
fields.Many2One('currency.currency', 'Currency'),
@@ -37,7 +37,8 @@
('normal', 'Normal'),
('distribution', 'Distribution'),
], 'Type', required=True)
- root = fields.Many2One('analytic_account.account', 'Root', select=True,
+ root = fields.Many2One(
+ 'analytic_account.account', "Root",
domain=[
('company', '=', Eval('company', -1)),
('parent', '=', None),
@@ -47,7 +48,8 @@
'invisible': Eval('type') == 'root',
'required': Eval('type') != 'root',
})
- parent = fields.Many2One('analytic_account.account', 'Parent', select=True,
+ parent = fields.Many2One(
+ 'analytic_account.account', "Parent",
domain=['OR',
('root', '=', Eval('root', -1)),
('parent', '=', None),
@@ -91,7 +93,11 @@
@classmethod
def __setup__(cls):
+ cls.code.search_unaccented = False
super(Account, cls).__setup__()
+ t = cls.__table__()
+ cls._sql_indexes.add(
+ Index(t, (t.code, Index.Similarity())))
cls._order.insert(0, ('code', 'ASC'))
cls._order.insert(1, ('name', 'ASC'))
@@ -308,7 +314,7 @@
"Analytic Account Distribution"
__name__ = 'analytic_account.account.distribution'
parent = fields.Many2One(
- 'analytic_account.account', "Parent", required=True, select=True)
+ 'analytic_account.account', "Parent", required=True)
root = fields.Function(
fields.Many2One('analytic_account.account', "Root"),
'on_change_with_root')
@@ -337,7 +343,7 @@
class AnalyticAccountEntry(ModelView, ModelSQL):
'Analytic Account Entry'
__name__ = 'analytic.account.entry'
- origin = fields.Reference('Origin', selection='get_origin', select=True)
+ origin = fields.Reference('Origin', selection='get_origin')
root = fields.Many2One(
'analytic_account.account', "Root Analytic", required=True,
domain=[
@@ -398,6 +404,7 @@
('root_origin_uniq', Unique(t, t.origin, t.root),
'analytic_account.msg_root_origin_unique'),
]
+ cls._sql_indexes.add(Index(t, (t.origin, Index.Equality())))
@classmethod
def _get_origin(cls):
diff -r ab59016bfe86 -r 5c89b1563670 line.py
--- a/line.py Fri Sep 16 23:37:38 2022 +0200
+++ b/line.py Tue Oct 11 00:44:49 2022 +0200
@@ -6,7 +6,7 @@
from sql import Literal
-from trytond.model import Check, ModelSQL, ModelView, fields
+from trytond.model import Check, Index, ModelSQL, ModelView, fields
from trytond.modules.currency.fields import Monetary
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval, PYSONEncoder
@@ -26,8 +26,9 @@
'on_change_with_currency')
company = fields.Function(fields.Many2One('company.company', 'Company'),
'on_change_with_company', searcher='search_company')
- account = fields.Many2One('analytic_account.account', 'Account',
- required=True, select=True, domain=[
+ account = fields.Many2One(
+ 'analytic_account.account', "Account", required=True,
+ domain=[
('type', 'not in', ['view', 'distribution']),
['OR',
('company', '=', None),
@@ -47,6 +48,10 @@
Check(t, t.credit * t.debit == 0),
'account.msg_line_debit_credit'),
]
+ cls._sql_indexes.update({
+ Index(t, (t.account, Index.Equality())),
+ Index(t, (t.date, Index.Range())),
+ })
cls._order.insert(0, ('date', 'ASC'))
@classmethod
@@ -175,7 +180,7 @@
analytic_state = fields.Selection([
('draft', 'Draft'),
('valid', 'Valid'),
- ], "Analytic State", readonly=True, select=True, sort=False)
+ ], "Analytic State", readonly=True, sort=False)
@classmethod
def __setup__(cls):