cashbook: optimize for speed for checking rows
This commit is contained in:
parent
f9e55fab77
commit
52011f5166
1 changed files with 22 additions and 8 deletions
30
book.py
30
book.py
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
from trytond.model import (
|
from trytond.model import (
|
||||||
Workflow, ModelView, ModelSQL, fields, Check, tree, Index)
|
Workflow, ModelView, ModelSQL, fields, Check, tree, Index)
|
||||||
from trytond.pyson import Eval, Or, Bool, Id, Len
|
from trytond.pyson import Eval, Or, Bool, Id
|
||||||
from trytond.exceptions import UserError
|
from trytond.exceptions import UserError
|
||||||
from trytond.i18n import gettext
|
from trytond.i18n import gettext
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
|
@ -62,9 +62,9 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
||||||
model_name='cashbook.type', ondelete='RESTRICT',
|
model_name='cashbook.type', ondelete='RESTRICT',
|
||||||
states={
|
states={
|
||||||
'readonly': Or(
|
'readonly': Or(
|
||||||
STATES['readonly'],
|
STATES['readonly'],
|
||||||
Len(Eval('lines')) > 0),
|
Eval('has_lines', False))},
|
||||||
}, depends=DEPENDS+['lines'])
|
depends=DEPENDS+['has_lines'])
|
||||||
feature = fields.Function(fields.Char(
|
feature = fields.Function(fields.Char(
|
||||||
string='Feature', readonly=True,
|
string='Feature', readonly=True,
|
||||||
states={'invisible': True}), 'on_change_with_feature')
|
states={'invisible': True}), 'on_change_with_feature')
|
||||||
|
@ -86,6 +86,9 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
||||||
string='Lines', field='cashbook',
|
string='Lines', field='cashbook',
|
||||||
model_name='cashbook.line',
|
model_name='cashbook.line',
|
||||||
states=STATES, depends=DEPENDS)
|
states=STATES, depends=DEPENDS)
|
||||||
|
has_lines = fields.Function(fields.Boolean(
|
||||||
|
string='Has Lines', readonly=True, states={'invisible': True}),
|
||||||
|
'on_change_with_has_lines')
|
||||||
reconciliations = fields.One2Many(
|
reconciliations = fields.One2Many(
|
||||||
string='Reconciliations',
|
string='Reconciliations',
|
||||||
field='cashbook', model_name='cashbook.recon',
|
field='cashbook', model_name='cashbook.recon',
|
||||||
|
@ -112,10 +115,10 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
||||||
states={
|
states={
|
||||||
'readonly': Or(
|
'readonly': Or(
|
||||||
STATES2['readonly'],
|
STATES2['readonly'],
|
||||||
Len(Eval('lines')) > 0),
|
Eval('has_lines', False)),
|
||||||
'invisible': STATES2['invisible'],
|
'invisible': STATES2['invisible'],
|
||||||
'required': ~STATES2['invisible'],
|
'required': ~STATES2['invisible'],
|
||||||
}, depends=DEPENDS2+['lines'])
|
}, depends=DEPENDS2+['has_lines'])
|
||||||
|
|
||||||
value_store = fields.One2Many(
|
value_store = fields.One2Many(
|
||||||
string='Values', model_name='cashbook.values', field='cashbook',
|
string='Values', model_name='cashbook.values', field='cashbook',
|
||||||
|
@ -155,8 +158,8 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
||||||
states={
|
states={
|
||||||
'readonly': Or(
|
'readonly': Or(
|
||||||
STATES2['readonly'],
|
STATES2['readonly'],
|
||||||
Len(Eval('lines', [])) > 0),
|
Eval('has_lines', False))},
|
||||||
}, depends=DEPENDS2+['lines'])
|
depends=DEPENDS2+['has_lines'])
|
||||||
currency_digits = fields.Function(fields.Integer(
|
currency_digits = fields.Function(fields.Integer(
|
||||||
string='Currency Digits',
|
string='Currency Digits',
|
||||||
readonly=True), 'on_change_with_currency_digits')
|
readonly=True), 'on_change_with_currency_digits')
|
||||||
|
@ -543,6 +546,17 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
||||||
record[2], record[5], record[3])
|
record[2], record[5], record[3])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@fields.depends('id')
|
||||||
|
def on_change_with_has_lines(self, name=None):
|
||||||
|
""" return True if cashbook has lines
|
||||||
|
(we dont use 'if self.lines:' this would slow down the client)
|
||||||
|
"""
|
||||||
|
Line = Pool().get('cashbook.line')
|
||||||
|
|
||||||
|
if Line.search_count([('cashbook', '=', self.id)]):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
@fields.depends('btype')
|
@fields.depends('btype')
|
||||||
def on_change_with_feature(self, name=None):
|
def on_change_with_feature(self, name=None):
|
||||||
""" get feature-set
|
""" get feature-set
|
||||||
|
|
Loading…
Reference in a new issue