optimize search-queries, line: fix state-selection

This commit is contained in:
Frederik Jaeckel 2023-07-24 17:31:34 +02:00
parent 50ce7f5dbc
commit 0e30725d1f
6 changed files with 19 additions and 19 deletions

14
line.py
View file

@ -23,7 +23,7 @@ sel_payee = [
('party.party', 'Party')
]
sel_linetype = [
sel_linestate = [
('edit', 'Edit'),
('check', 'Checked'),
('recon', 'Reconciled'),
@ -351,7 +351,7 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
# allow cashbook-line at range-limits
if Recon.search_count([
('state', 'in', ['check', 'done']),
('cashbook.id', '=', line.cashbook.id),
('cashbook', '=', line.cashbook.id),
('date_from', '<', line.date),
('date_to', '>', line.date)]) > 0:
raise UserError(gettext(
@ -362,7 +362,7 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
# reconciliations exist
if Recon.search_count([
('state', 'in', ['check', 'done']),
('cashbook.id', '=', line.cashbook.id),
('cashbook', '=', line.cashbook.id),
['OR',
('date_from', '=', line.date),
('date_to', '=', line.date)]]) > 1:
@ -727,7 +727,7 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
end_value = None
recons = Reconciliation.search([
('cashbook.id', '=', line.cashbook.id),
('cashbook', '=', line.cashbook.id),
('date_to', '<=', line2.date),
('state', '=', 'done'),
], order=[('date_from', 'DESC')], limit=1)
@ -737,14 +737,14 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
('date', '<=', line2.date),
['OR',
('reconciliation', '=', None),
('reconciliation.id', '!=', recons[0])],
('reconciliation', '!=', recons[0])],
])
end_value = getattr(recons[0], 'end_%s' % field_name)
return (query2, end_value)
if line.cashbook:
query = [
('cashbook.id', '=', line.cashbook.id),
('cashbook', '=', line.cashbook.id),
]
balance = Decimal('0.0')
@ -754,7 +754,7 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
if line.reconciliation:
if line.reconciliation.state == 'done':
query.append(
('reconciliation.id', '=', line.reconciliation.id),
('reconciliation', '=', line.reconciliation.id),
)
balance = getattr(
line.reconciliation, 'start_%s' % field_name)