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
28
book.py
28
book.py
|
@ -5,7 +5,7 @@
|
|||
|
||||
from trytond.model import (
|
||||
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.i18n import gettext
|
||||
from trytond.transaction import Transaction
|
||||
|
@ -63,8 +63,8 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
|||
states={
|
||||
'readonly': Or(
|
||||
STATES['readonly'],
|
||||
Len(Eval('lines')) > 0),
|
||||
}, depends=DEPENDS+['lines'])
|
||||
Eval('has_lines', False))},
|
||||
depends=DEPENDS+['has_lines'])
|
||||
feature = fields.Function(fields.Char(
|
||||
string='Feature', readonly=True,
|
||||
states={'invisible': True}), 'on_change_with_feature')
|
||||
|
@ -86,6 +86,9 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
|||
string='Lines', field='cashbook',
|
||||
model_name='cashbook.line',
|
||||
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(
|
||||
string='Reconciliations',
|
||||
field='cashbook', model_name='cashbook.recon',
|
||||
|
@ -112,10 +115,10 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
|||
states={
|
||||
'readonly': Or(
|
||||
STATES2['readonly'],
|
||||
Len(Eval('lines')) > 0),
|
||||
Eval('has_lines', False)),
|
||||
'invisible': STATES2['invisible'],
|
||||
'required': ~STATES2['invisible'],
|
||||
}, depends=DEPENDS2+['lines'])
|
||||
}, depends=DEPENDS2+['has_lines'])
|
||||
|
||||
value_store = fields.One2Many(
|
||||
string='Values', model_name='cashbook.values', field='cashbook',
|
||||
|
@ -155,8 +158,8 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
|||
states={
|
||||
'readonly': Or(
|
||||
STATES2['readonly'],
|
||||
Len(Eval('lines', [])) > 0),
|
||||
}, depends=DEPENDS2+['lines'])
|
||||
Eval('has_lines', False))},
|
||||
depends=DEPENDS2+['has_lines'])
|
||||
currency_digits = fields.Function(fields.Integer(
|
||||
string='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])
|
||||
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')
|
||||
def on_change_with_feature(self, name=None):
|
||||
""" get feature-set
|
||||
|
|
Loading…
Reference in a new issue