optimize search-queries, line: fix state-selection

This commit is contained in:
Frederik Jaeckel 2023-07-24 17:31:34 +02:00
parent e605d5f0d3
commit 90298d3eb8
6 changed files with 20 additions and 20 deletions

16
line.py
View file

@ -23,7 +23,7 @@ sel_payee = [
('party.party', 'Party')
]
sel_linetype = [
sel_linestate = [
('edit', 'Edit'),
('check', 'Checked'),
('recon', 'Reconciled'),
@ -197,7 +197,7 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
state = fields.Selection(
string='State', required=True, readonly=True,
selection=sel_linetype)
selection=sel_linestate)
state_string = state.translated('state')
state_cashbook = fields.Function(fields.Selection(
string='State of Cashbook',
@ -375,7 +375,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(
@ -386,7 +386,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:
@ -751,7 +751,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)
@ -761,14 +761,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')
@ -778,7 +778,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)