line: darstellung beschleunigt

This commit is contained in:
Frederik Jaeckel 2022-09-03 20:39:20 +02:00
parent bb24a94cd1
commit b4e7cface3
4 changed files with 41 additions and 15 deletions

45
line.py
View file

@ -57,8 +57,10 @@ class Line(Workflow, ModelSQL, ModelView):
month = fields.Function(fields.Integer(string='Month', readonly=True),
'on_change_with_month', searcher='search_month')
number = fields.Char(string='Number', readonly=True)
description = fields.Text(string='Description',
description = fields.Text(string='Description', select=True,
states=STATES, depends=DEPENDS)
descr_short = fields.Function(fields.Char(string='Description', readonly=True),
'on_change_with_descr_short', searcher='search_descr_short')
category = fields.Many2One(string='Category',
model_name='cashbook.category', ondelete='RESTRICT',
states={
@ -414,6 +416,13 @@ class Line(Workflow, ModelSQL, ModelView):
return [tab2]
@staticmethod
def order_descr_short(tables):
""" order by 'description'
"""
table, _ = tables[None]
return [table.description]
@classmethod
def search_payee(cls, names, clause):
""" search in payee for party or cashbook
@ -454,6 +463,12 @@ class Line(Workflow, ModelSQL, ModelView):
"""
return [('cashbook.state',) + tuple(clause[1:])]
@classmethod
def search_descr_short(cls, names, clause):
""" search in description
"""
return [('description',) + tuple(clause[1:])]
@fields.depends('amount', 'splitlines')
def on_change_splitlines(self):
""" update amount if splitlines change
@ -481,6 +496,13 @@ class Line(Workflow, ModelSQL, ModelView):
else :
self.splitlines = []
@fields.depends('description')
def on_change_with_descr_short(self, name=None):
""" to speed up list-view
"""
if self.description:
return self.description[:25]
@fields.depends('party', 'booktransf', 'bookingtype')
def on_change_with_payee(self, name=None):
""" get party or cashbook
@ -564,6 +586,7 @@ class Line(Workflow, ModelSQL, ModelView):
generate query
"""
query2 = []
end_amount = None
recons = Reconciliation.search([
('cashbook.id', '=', self.cashbook.id),
@ -579,11 +602,8 @@ class Line(Workflow, ModelSQL, ModelView):
('reconciliation.id', '!=', recons[0]),
],
])
return (query2, recons[0].end_amount)
from datetime import datetime
dt1 = datetime.now()
print('\n## on_change_with_balance', dt1)
end_amount = recons[0].end_amount
return (query2, end_amount)
if self.cashbook:
query = [
@ -601,22 +621,21 @@ class Line(Workflow, ModelSQL, ModelView):
)
balance = self.reconciliation.start_amount
else :
(query2, balance) = get_from_last_recon(self)
(query2, balance2) = get_from_last_recon(self)
query.extend(query2)
if balance2 is not None:
balance = balance2
else :
(query2, balance) = get_from_last_recon(self)
(query2, balance2) = get_from_last_recon(self)
query.extend(query2)
if balance2 is not None:
balance = balance2
print('-- 1:', (datetime.now() - dt1))
print('-- 2:', (datetime.now() - dt1), ', query:', query)
lines = Line.search(query)
print('-- 3:', (datetime.now() - dt1), ', lines:',len(lines))
for line in lines:
balance += line.credit - line.debit
if line.id == self.id:
break
print('-- 4:', (datetime.now() - dt1))
return balance
@classmethod

View file

@ -642,6 +642,10 @@ msgctxt "field:cashbook.line,description:"
msgid "Description"
msgstr "Beschreibung"
msgctxt "field:cashbook.line,descr_short:"
msgid "Description"
msgstr "Beschreibung"
msgctxt "field:cashbook.line,state:"
msgid "State"
msgstr "Status"

View file

@ -598,6 +598,10 @@ msgctxt "field:cashbook.line,description:"
msgid "Description"
msgstr "Description"
msgctxt "field:cashbook.line,descr_short:"
msgid "Description"
msgstr "Description"
msgctxt "field:cashbook.line,state:"
msgid "State"
msgstr "State"

View file

@ -7,8 +7,7 @@ full copyright notices and license terms. -->
<field name="number"/>
<field name="date"/>
<field name="payee"/>
<field name="category_view"/>
<field name="description" expand="1"/>
<field name="descr_short" expand="1"/>
<field name="credit" sum="Credit"/>
<field name="debit" sum="Debit"/>
<field name="balance"/>