changeset df2d8e96dbe9 in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset&node=df2d8e96dbe9
description:
Use declarative index definition for ModelSQL
issue5757
review361251002
diffstat:
account.py | 51 ++++++++++++++++++++++--------------
fiscalyear.py | 2 +-
journal.py | 2 +-
move.py | 80 +++++++++++++++++++++++++++++++++++++---------------------
party.py | 2 +-
period.py | 21 +++++++++-----
tax.py | 34 +++++++++++++-----------
7 files changed, 116 insertions(+), 76 deletions(-)
diffs (477 lines):
diff -r cccc5eb9493b -r df2d8e96dbe9 account.py
--- a/account.py Sat Oct 01 15:37:36 2022 +0200
+++ b/account.py Tue Oct 11 00:44:48 2022 +0200
@@ -15,7 +15,7 @@
from trytond import backend
from trytond.i18n import gettext
from trytond.model import (
- Check, ModelSQL, ModelView, Unique, fields, sequence_ordered, tree)
+ Check, Index, ModelSQL, ModelView, Unique, fields, sequence_ordered, tree)
from trytond.model.exceptions import AccessError
from trytond.modules.currency.fields import Monetary
from trytond.pool import Pool
@@ -506,8 +506,8 @@
class Mixin:
__slots__ = ()
_order_name = 'rec_name'
- name = fields.Char('Name', required=True, select=True)
- code = fields.Char('Code', select=True)
+ name = fields.Char("Name", required=True)
+ code = fields.Char("Code")
closed = fields.Boolean(
"Closed",
@@ -659,8 +659,8 @@
'account.account.type.template', "Debit Type", ondelete="RESTRICT")
credit_type = fields.Many2One(
'account.account.type.template', "Credit Type", ondelete="RESTRICT")
- parent = fields.Many2One('account.account.template', 'Parent', select=True,
- ondelete="RESTRICT")
+ parent = fields.Many2One(
+ 'account.account.template', "Parent", ondelete="RESTRICT")
childs = fields.One2Many('account.account.template', 'parent', 'Children')
taxes = fields.Many2Many('account.account.template-account.tax.template',
'account', 'tax', 'Default Taxes',
@@ -826,10 +826,12 @@
'Account Template - Tax Template'
__name__ = 'account.account.template-account.tax.template'
_table = 'account_account_template_tax_rel'
- account = fields.Many2One('account.account.template', 'Account Template',
- ondelete='CASCADE', select=True, required=True)
- tax = fields.Many2One('account.tax.template', 'Tax Template',
- ondelete='RESTRICT', select=True, required=True)
+ account = fields.Many2One(
+ 'account.account.template', "Account Template",
+ ondelete='CASCADE', required=True)
+ tax = fields.Many2One(
+ 'account.tax.template', "Tax Template",
+ ondelete='RESTRICT', required=True)
class Account(
@@ -888,13 +890,13 @@
],
help="The type used if not empty and debit < credit.")
parent = fields.Many2One(
- 'account.account', 'Parent', select=True,
+ 'account.account', "Parent",
left="left", right="right", ondelete="RESTRICT", states=_states,
domain=[
('company', '=', Eval('company', -1)),
])
- left = fields.Integer('Left', required=True, select=True)
- right = fields.Integer('Right', required=True, select=True)
+ left = fields.Integer("Left", required=True)
+ right = fields.Integer("Right", required=True)
childs = fields.One2Many(
'account.account', 'parent', "Children",
domain=[
@@ -968,6 +970,11 @@
('only_one_debit_credit_types', Check(
table, (table.debit_type + table.credit_type) == Null),
'account.msg_only_one_debit_credit_types'))
+ cls._sql_indexes.add(
+ Index(
+ table,
+ (table.left, Index.Range()),
+ (table.right, Index.Range())))
@classmethod
def __register__(cls, module_name):
@@ -1620,10 +1627,9 @@
It is used to deferral the debit/credit of account by fiscal year.
'''
__name__ = 'account.account.deferral'
- account = fields.Many2One('account.account', 'Account', required=True,
- select=True)
- fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
- required=True, select=True)
+ account = fields.Many2One('account.account', "Account", required=True)
+ fiscalyear = fields.Many2One(
+ 'account.fiscalyear', "Fiscal Year", required=True)
debit = Monetary(
"Debit", currency='currency', digits='currency', required=True)
credit = Monetary(
@@ -1651,6 +1657,11 @@
('deferral_uniq', Unique(t, t.account, t.fiscalyear),
'account.msg_deferral_unique'),
]
+ cls._sql_indexes.add(
+ Index(
+ t,
+ (t.fiscalyear, Index.Equality()),
+ (t.account, Index.Equality())))
@classmethod
def __register__(cls, module_name):
@@ -1758,10 +1769,10 @@
'Account - Tax'
__name__ = 'account.account-account.tax'
_table = 'account_account_tax_rel'
- account = fields.Many2One('account.account', 'Account', ondelete='CASCADE',
- select=True, required=True)
- tax = fields.Many2One('account.tax', 'Tax', ondelete='RESTRICT',
- select=True, required=True)
+ account = fields.Many2One(
+ 'account.account', "Account", ondelete='CASCADE', required=True)
+ tax = fields.Many2One(
+ 'account.tax', "Tax", ondelete='RESTRICT', required=True)
class AccountContext(ModelView):
diff -r cccc5eb9493b -r df2d8e96dbe9 fiscalyear.py
--- a/fiscalyear.py Sat Oct 01 15:37:36 2022 +0200
+++ b/fiscalyear.py Tue Oct 11 00:44:48 2022 +0200
@@ -49,7 +49,7 @@
('company', '=', Eval('company')),
])
company = fields.Many2One(
- 'company.company', "Company", required=True, select=True)
+ 'company.company', "Company", required=True)
icon = fields.Function(fields.Char("Icon"), 'get_icon')
@classmethod
diff -r cccc5eb9493b -r df2d8e96dbe9 journal.py
--- a/journal.py Sat Oct 01 15:37:36 2022 +0200
+++ b/journal.py Tue Oct 11 00:44:48 2022 +0200
@@ -177,7 +177,7 @@
"Journal Sequence"
__name__ = 'account.journal.sequence'
journal = fields.Many2One(
- 'account.journal', "Journal", ondelete='CASCADE', select=True,
+ 'account.journal', "Journal", ondelete='CASCADE',
context={
'company': Eval('company', -1),
},
diff -r cccc5eb9493b -r df2d8e96dbe9 move.py
--- a/move.py Sat Oct 01 15:37:36 2022 +0200
+++ b/move.py Tue Oct 11 00:44:48 2022 +0200
@@ -14,7 +14,8 @@
from trytond import backend
from trytond.config import config
from trytond.i18n import gettext
-from trytond.model import Check, DeactivableMixin, ModelSQL, ModelView, fields
+from trytond.model import (
+ Check, DeactivableMixin, Index, ModelSQL, ModelView, fields)
from trytond.model.exceptions import AccessError
from trytond.modules.currency.fields import Monetary
from trytond.pool import Pool
@@ -55,8 +56,7 @@
('state', '=', 'open'),
()),
],
- states=_MOVE_STATES,
- select=True)
+ states=_MOVE_STATES)
journal = fields.Many2One('account.journal', 'Journal', required=True,
states={
'readonly': Eval('number') & Eval('journal'),
@@ -65,8 +65,7 @@
'company': Eval('company', -1),
},
depends={'company'})
- date = fields.Date('Effective Date', required=True, select=True,
- states=_MOVE_STATES)
+ date = fields.Date('Effective Date', required=True, states=_MOVE_STATES)
post_date = fields.Date('Post Date', readonly=True)
description = fields.Char('Description', states=_MOVE_STATES)
origin = fields.Reference('Origin', selection='get_origin',
@@ -74,7 +73,7 @@
state = fields.Selection([
('draft', 'Draft'),
('posted', 'Posted'),
- ], 'State', required=True, readonly=True, select=True, sort=False)
+ ], 'State', required=True, readonly=True, sort=False)
lines = fields.One2Many('account.move.line', 'move', 'Lines',
states=_MOVE_STATES, depends={'company'},
context={
@@ -86,6 +85,7 @@
@classmethod
def __setup__(cls):
super(Move, cls).__setup__()
+ t = cls.__table__()
cls.create_date.select = True
cls._check_modify_exclude = ['lines']
cls._order.insert(0, ('date', 'DESC'))
@@ -100,6 +100,14 @@
'post': RPC(
readonly=False, instantiate=0, fresh_session=True),
})
+ cls._sql_indexes.update({
+ Index(t, (t.period, Index.Equality())),
+ Index(t, (t.date, Index.Range()), (t.number, Index.Range())),
+ Index(
+ t,
+ (t.journal, Index.Equality()),
+ (t.period, Index.Equality())),
+ })
@classmethod
def __register__(cls, module_name):
@@ -125,9 +133,6 @@
where=period.id == sql_table.period)
cursor.execute(*sql_table.update([sql_table.company], [value]))
- table = cls.__table_handler__(module_name)
- table.index_action(['journal', 'period'], 'add')
-
@classmethod
def order_number(cls, tables):
table, _ = tables[None]
@@ -491,16 +496,23 @@
domain=[
('move.company', '=', Eval('company', -1)),
])
- date = fields.Date('Date', required=True, select=True,
+ date = fields.Date(
+ "Date", required=True,
help='Highest date of the reconciled lines.')
delegate_to = fields.Many2One(
- 'account.move.line', "Delegate To", ondelete="RESTRICT", select=True,
+ 'account.move.line', "Delegate To", ondelete="RESTRICT",
domain=[
('move.company', '=', Eval('company', -1)),
],
help="The line to which the reconciliation status is delegated.")
@classmethod
+ def __setup__(cls):
+ super().__setup__()
+ t = cls.__table__()
+ cls._sql_indexes.add(Index(t, (t.date, Index.Range())))
+
+ @classmethod
def __register__(cls, module_name):
cursor = Transaction().connection.cursor()
table = cls.__table_handler__(module_name)
@@ -757,8 +769,9 @@
context={
'company': Eval('company', -1),
},
- select=True, states=_states, depends={'company'})
- move = fields.Many2One('account.move', 'Move', select=True, required=True,
+ states=_states, depends={'company'})
+ move = fields.Many2One(
+ 'account.move', "Move", required=True,
ondelete='CASCADE',
states={
'required': False,
@@ -819,7 +832,8 @@
second_currency_required = fields.Function(
fields.Many2One('currency.currency', "Second Currency Required"),
'on_change_with_second_currency_required')
- party = fields.Many2One('party.party', 'Party', select=True,
+ party = fields.Many2One(
+ 'party.party', "Party",
states={
'required': Eval('party_required', False),
'invisible': ~Eval('party_required', False),
@@ -844,9 +858,10 @@
state = fields.Selection([
('draft', 'Draft'),
('valid', 'Valid'),
- ], 'State', readonly=True, required=True, select=True, sort=False)
- reconciliation = fields.Many2One('account.move.reconciliation',
- 'Reconciliation', readonly=True, ondelete='SET NULL', select=True)
+ ], 'State', readonly=True, required=True, sort=False)
+ reconciliation = fields.Many2One(
+ 'account.move.reconciliation', 'Reconciliation',
+ readonly=True, ondelete='SET NULL')
reconciliations_delegated = fields.One2Many(
'account.move.reconciliation', 'delegate_to',
"Reconciliations Delegated", readonly=True)
@@ -896,18 +911,25 @@
# Do not cache default_date nor default_move
cls.__rpc__['default_get'].cache = None
cls._order[0] = ('id', 'DESC')
-
- @classmethod
- def __register__(cls, module_name):
- super(Line, cls).__register__(module_name)
-
- table = cls.__table__()
- table_h = cls.__table_handler__(module_name)
- # Index for General Ledger
- table_h.index_action(['move', 'account'], 'add')
- # Index for account.account.party
- table_h.index_action(
- ['account', 'party', 'id'], 'add', where=table.party != Null)
+ cls._sql_indexes.update({
+ Index(
+ table,
+ (table.account, Index.Equality()),
+ (table.party, Index.Equality())),
+ Index(table, (table.reconciliation, Index.Equality())),
+ # Index for General Ledger
+ Index(
+ table,
+ (table.move, Index.Equality()),
+ (table.account, Index.Equality())),
+ # Index for account.account.party
+ Index(
+ table,
+ (table.account, Index.Equality()),
+ (table.party, Index.Equality()),
+ (table.id, Index.Equality()),
+ where=table.party != Null),
+ })
@classmethod
def default_date(cls):
diff -r cccc5eb9493b -r df2d8e96dbe9 party.py
--- a/party.py Sat Oct 01 15:37:36 2022 +0200
+++ b/party.py Tue Oct 11 00:44:48 2022 +0200
@@ -293,7 +293,7 @@
"Party Account"
__name__ = 'party.party.account'
party = fields.Many2One(
- 'party.party', "Party", ondelete='CASCADE', select=True,
+ 'party.party', "Party", ondelete='CASCADE',
context={
'company': Eval('company', -1),
},
diff -r cccc5eb9493b -r df2d8e96dbe9 period.py
--- a/period.py Sat Oct 01 15:37:36 2022 +0200
+++ b/period.py Tue Oct 11 00:44:48 2022 +0200
@@ -3,7 +3,7 @@
from trytond.const import OPERATORS
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.pool import Pool
from trytond.pyson import Eval, Id
@@ -23,13 +23,11 @@
__name__ = 'account.period'
name = fields.Char('Name', required=True)
start_date = fields.Date('Starting Date', required=True, states=_STATES,
- domain=[('start_date', '<=', Eval('end_date', None))],
- select=True)
+ domain=[('start_date', '<=', Eval('end_date', None))])
end_date = fields.Date('Ending Date', required=True, states=_STATES,
- domain=[('end_date', '>=', Eval('start_date', None))],
- select=True)
- fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
- required=True, states=_STATES, select=True)
+ domain=[('end_date', '>=', Eval('start_date', None))])
+ fiscalyear = fields.Many2One(
+ 'account.fiscalyear', "Fiscal Year", required=True, states=_STATES)
state = fields.Selection([
('open', 'Open'),
('close', 'Close'),
@@ -48,7 +46,7 @@
('standard', 'Standard'),
('adjustment', 'Adjustment'),
], 'Type', required=True,
- states=_STATES, select=True)
+ states=_STATES)
company = fields.Function(fields.Many2One('company.company', 'Company',),
'on_change_with_company', searcher='search_company')
icon = fields.Function(fields.Char("Icon"), 'get_icon')
@@ -56,7 +54,14 @@
@classmethod
def __setup__(cls):
super(Period, cls).__setup__()
+ t = cls.__table__()
cls.__access__.add('fiscalyear')
+ cls._sql_indexes.add(
+ Index(
+ t,
+ (t.start_date, Index.Range()),
+ (t.end_date, Index.Range()),
+ order='DESC'))
cls._order.insert(0, ('start_date', 'DESC'))
cls._transitions |= set((
('open', 'close'),
diff -r cccc5eb9493b -r df2d8e96dbe9 tax.py
--- a/tax.py Sat Oct 01 15:37:36 2022 +0200
+++ b/tax.py Tue Oct 11 00:44:48 2022 +0200
@@ -12,7 +12,7 @@
from trytond import backend
from trytond.i18n import gettext
from trytond.model import (
- DeactivableMixin, MatchMixin, ModelSQL, ModelView, fields,
+ DeactivableMixin, Index, MatchMixin, ModelSQL, ModelView, fields,
sequence_ordered, tree)
from trytond.model.exceptions import AccessError
from trytond.modules.currency.fields import Monetary
@@ -129,12 +129,11 @@
'readonly': (Bool(Eval('template', -1))
& ~Eval('template_override', False)),
}
- name = fields.Char('Name', required=True, select=True, states=_states)
- code = fields.Char('Code', select=True, states=_states)
- company = fields.Many2One('company.company', 'Company', required=True,
- select=True)
+ name = fields.Char('Name', required=True, states=_states)
+ code = fields.Char('Code', states=_states)
+ company = fields.Many2One('company.company', 'Company', required=True)
parent = fields.Many2One(
- 'account.tax.code', "Parent", select=True, states=_states,
+ 'account.tax.code', "Parent", states=_states,
domain=[
('company', '=', Eval('company', -1)),
])
@@ -160,7 +159,11 @@
@classmethod
def __setup__(cls):
+ cls.code.search_unaccented = False
super(TaxCode, cls).__setup__()
+ t = cls.__table__()
+ cls._sql_indexes.add(
+ Index(t, (t.code, Index.Similarity())))
for date in [cls.start_date, cls.end_date]:
date.states = {
'readonly': (Bool(Eval('template', -1))
@@ -799,8 +802,7 @@
domain=[
('company', '=', Eval('company', -1)),
])
- company = fields.Many2One(
- 'company.company', "Company", required=True, select=True)
+ company = fields.Many2One('company.company', "Company", required=True)
invoice_account = fields.Many2One('account.account', 'Invoice Account',
domain=[
('company', '=', Eval('company')),
@@ -1295,13 +1297,13 @@
('tax', "Tax"),
('base', "Base"),
], "Type", required=True)
- tax = fields.Many2One('account.tax', 'Tax', select=True,
- ondelete='RESTRICT', required=True,
+ tax = fields.Many2One(
+ 'account.tax', "Tax", ondelete='RESTRICT', required=True,
domain=[
('company', '=', Eval('company', -1)),
])
- move_line = fields.Many2One('account.move.line', 'Move Line',
- required=True, select=True, ondelete='CASCADE')
+ move_line = fields.Many2One(
+ 'account.move.line', "Move Line", required=True, ondelete='CASCADE')
company = fields.Function(fields.Many2One('company.company', 'Company'),
'on_change_with_company')
@@ -1469,8 +1471,7 @@
}
name = fields.Char('Name', required=True, states=_states)
kind = fields.Selection(KINDS, 'Kind', required=True, states=_states)
- company = fields.Many2One(
- 'company.company', "Company", required=True, select=True)
+ company = fields.Many2One('company.company', "Company", required=True,)
lines = fields.One2Many('account.tax.rule.line', 'rule', 'Lines')
template = fields.Many2One('account.tax.rule.template', 'Template')
template_override = fields.Boolean("Override Template",
@@ -1665,8 +1666,9 @@
'readonly': (Bool(Eval('template', -1))
& ~Eval('template_override', False)),
}
- rule = fields.Many2One('account.tax.rule', 'Rule', required=True,
- select=True, ondelete='CASCADE', states=_states)
+ rule = fields.Many2One(
+ 'account.tax.rule', "Rule",
+ required=True, ondelete='CASCADE', states=_states)
start_date = fields.Date("Starting Date")
end_date = fields.Date("Ending Date")
group = fields.Many2One('account.tax.group', 'Tax Group',