line: darstellung beschleunigt

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

View file

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

View file

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

View file

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