optimize search-queries, line: fix state-selection
This commit is contained in:
parent
e605d5f0d3
commit
90298d3eb8
6 changed files with 20 additions and 20 deletions
2
book.py
2
book.py
|
@ -574,7 +574,7 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
|||
'defbook', 'book1', 'book2', 'book3',
|
||||
'book4', 'book5']:
|
||||
cfg1 = ConfigUser.search([
|
||||
('iduser.id', '=', book.owner.id),
|
||||
('iduser', '=', book.owner.id),
|
||||
('%s.id' % x, '=', book.id)])
|
||||
if len(cfg1) > 0:
|
||||
to_write_config.extend([cfg1, {x: None}])
|
||||
|
|
16
line.py
16
line.py
|
@ -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)
|
||||
|
|
|
@ -183,7 +183,7 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
if Line.search_count([
|
||||
('date', '>', reconciliation.date_from),
|
||||
('date', '<', reconciliation.date_to),
|
||||
('cashbook.id', '=', reconciliation.cashbook.id),
|
||||
('cashbook', '=', reconciliation.cashbook.id),
|
||||
('state', 'not in', ['check', 'recon']),
|
||||
]) > 0:
|
||||
raise UserError(gettext(
|
||||
|
@ -224,7 +224,7 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
lines = Line.search([
|
||||
('date', '>=', reconciliation.date_from),
|
||||
('date', '<=', reconciliation.date_to),
|
||||
('cashbook.id', '=', reconciliation.cashbook.id),
|
||||
('cashbook', '=', reconciliation.cashbook.id),
|
||||
('reconciliation', '=', None),
|
||||
('state', 'in', ['check', 'recon']),
|
||||
])
|
||||
|
@ -315,7 +315,7 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
|
||||
# deny if there are lines not linked to reconciliation
|
||||
if Line.search_count([
|
||||
('cashbook.id', '=', reconciliation.cashbook.id),
|
||||
('cashbook', '=', reconciliation.cashbook.id),
|
||||
('reconciliation', '=', None),
|
||||
['OR',
|
||||
[ # lines inside of date-range
|
||||
|
@ -405,7 +405,7 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
if self.cashbook:
|
||||
if self.date_from is not None:
|
||||
reconciliations = Recon.search([
|
||||
('cashbook.id', '=', self.cashbook.id),
|
||||
('cashbook', '=', self.cashbook.id),
|
||||
('date_from', '<', self.date_from),
|
||||
], order=[('date_from', 'DESC')], limit=1)
|
||||
if len(reconciliations) > 0:
|
||||
|
@ -457,7 +457,7 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
|
||||
# set date_from to date_to of predecessor
|
||||
recons = Recon.search([
|
||||
('cashbook.id', '=', id_cashbook),
|
||||
('cashbook', '=', id_cashbook),
|
||||
], order=[('date_to', 'DESC')], limit=1)
|
||||
if len(recons) > 0:
|
||||
values['date_from'] = recons[0].date_to
|
||||
|
@ -466,7 +466,7 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
|
||||
# set date_to to day of last 'checked'-booking in selected cashbook
|
||||
lines = Line.search([
|
||||
('cashbook.id', '=', id_cashbook),
|
||||
('cashbook', '=', id_cashbook),
|
||||
('state', '=', 'check'),
|
||||
('reconciliation', '=', None),
|
||||
], order=[('date', 'DESC')], limit=1)
|
||||
|
|
|
@ -9,7 +9,7 @@ from trytond.pool import Pool
|
|||
from trytond.pyson import Eval, If
|
||||
from trytond.report import Report
|
||||
from trytond.i18n import gettext
|
||||
from .line import sel_bookingtype, STATES, DEPENDS
|
||||
from .line import sel_bookingtype, sel_linestate, STATES, DEPENDS
|
||||
from .book import sel_state_book
|
||||
from .mixin import SecondCurrencyMixin, MemCacheIndexMx
|
||||
|
||||
|
@ -90,7 +90,7 @@ class SplitLine(SecondCurrencyMixin, MemCacheIndexMx, ModelSQL, ModelView):
|
|||
selection=sel_bookingtype), 'on_change_with_bookingtype')
|
||||
state = fields.Function(fields.Selection(
|
||||
string='State', readonly=True,
|
||||
selection=sel_linetype), 'on_change_with_state')
|
||||
selection=sel_linestate), 'on_change_with_state')
|
||||
cashbook = fields.Function(fields.Many2One(
|
||||
string='Cashbook',
|
||||
readonly=True, states={'invisible': True}, model_name='cashbook.book'),
|
||||
|
|
|
@ -152,7 +152,7 @@ class EnterBookingWizard(Wizard):
|
|||
'cashbooks': [x.id for x in Cashbook.search([
|
||||
('state', '=', 'open'),
|
||||
('btype', '!=', None),
|
||||
('owner.id', '=', Transaction().user),
|
||||
('owner', '=', Transaction().user),
|
||||
('id', 'in', book_ids),
|
||||
])],
|
||||
'bookingtype': getattr(self.start, 'bookingtype', 'out'),
|
||||
|
|
|
@ -55,7 +55,7 @@ class RunCbReportStart(ModelView):
|
|||
|
||||
if self.cashbook:
|
||||
recons = Recon2.search([
|
||||
('cashbook.id', '=', self.cashbook.id),
|
||||
('cashbook', '=', self.cashbook.id),
|
||||
], order=[('date_from', 'DESC')])
|
||||
return [x.id for x in recons]
|
||||
|
||||
|
@ -103,7 +103,7 @@ class RunCbReport(Wizard):
|
|||
result['cashbook'] = result['cashbooks'][0]
|
||||
|
||||
recons = Recon2.search([
|
||||
('cashbook.id', '=', result['cashbook']),
|
||||
('cashbook', '=', result['cashbook']),
|
||||
], order=[('date_from', 'DESC')])
|
||||
if len(recons) > 0:
|
||||
result['reconciliations'] = [x.id for x in recons]
|
||||
|
|
Loading…
Reference in a new issue