reconciliation: wf-values ausgelagert
This commit is contained in:
parent
b809d51fe0
commit
2b4d69736b
2 changed files with 54 additions and 37 deletions
|
@ -168,6 +168,50 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
dateto = Report.format_date(reconciliation.date_to),
|
||||
))
|
||||
|
||||
@classmethod
|
||||
def get_values_wfedit(cls, reconciliation):
|
||||
""" get values for 'to_write' in wf-edit
|
||||
"""
|
||||
values = {
|
||||
'start_amount': Decimal('0.0'),
|
||||
'end_amount': Decimal('0.0'),
|
||||
}
|
||||
|
||||
# unlink lines from reconciliation
|
||||
if len(reconciliation.lines) > 0:
|
||||
values['lines'] = [('remove', [x.id for x in reconciliation.lines])]
|
||||
return values
|
||||
|
||||
@classmethod
|
||||
def get_values_wfcheck(cls, reconciliation):
|
||||
""" get values for 'to_write' in wf-check
|
||||
"""
|
||||
Line = Pool().get('cashbook.line')
|
||||
|
||||
values = {}
|
||||
if reconciliation.predecessor:
|
||||
values['start_amount'] = reconciliation.predecessor.end_amount
|
||||
else :
|
||||
values['start_amount'] = Decimal('0.0')
|
||||
values['end_amount'] = values['start_amount']
|
||||
|
||||
# add 'checked'-lines to reconciliation
|
||||
lines = Line.search([
|
||||
('date', '>=', reconciliation.date_from),
|
||||
('date', '<=', reconciliation.date_to),
|
||||
('cashbook.id', '=', reconciliation.cashbook.id),
|
||||
('reconciliation', '=', None),
|
||||
('state', 'in', ['check', 'recon']),
|
||||
])
|
||||
if len(lines) > 0:
|
||||
values['lines'] = [('add', [x.id for x in lines])]
|
||||
|
||||
# add amounts of new lines
|
||||
values['end_amount'] += sum([x.credit - x.debit for x in lines])
|
||||
# add amounts of already linked lines
|
||||
values['end_amount'] += sum([x.credit - x.debit for x in reconciliation.lines])
|
||||
return values
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('edit')
|
||||
|
@ -178,16 +222,10 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
|
||||
to_write = []
|
||||
for reconciliation in reconciliations:
|
||||
values = {
|
||||
'start_amount': Decimal('0.0'),
|
||||
'end_amount': Decimal('0.0'),
|
||||
}
|
||||
|
||||
# unlink lines from reconciliation
|
||||
if len(reconciliation.lines) > 0:
|
||||
values['lines'] = [('remove', [x.id for x in reconciliation.lines])]
|
||||
|
||||
to_write.extend([[reconciliation], values])
|
||||
to_write.extend([
|
||||
[reconciliation],
|
||||
cls.get_values_wfedit(reconciliation),
|
||||
])
|
||||
|
||||
if len(to_write) > 0:
|
||||
Recon.write(*to_write)
|
||||
|
@ -199,16 +237,12 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
""" checked: add lines of book in date-range to reconciliation,
|
||||
state of lines must be 'checked'
|
||||
"""
|
||||
pool = Pool()
|
||||
Line = pool.get('cashbook.line')
|
||||
Recon = pool.get('cashbook.recon')
|
||||
Recon = Pool().get('cashbook.recon')
|
||||
|
||||
cls.check_lines_not_checked(reconciliations)
|
||||
|
||||
to_write = []
|
||||
for reconciliation in reconciliations:
|
||||
values = {}
|
||||
|
||||
if reconciliation.predecessor:
|
||||
# predecessor must be 'done'
|
||||
if reconciliation.predecessor.state != 'done':
|
||||
|
@ -226,28 +260,11 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
dateto = Report.format_date(reconciliation.predecessor.date_to),
|
||||
recname = reconciliation.rec_name,
|
||||
))
|
||||
values['start_amount'] = reconciliation.predecessor.end_amount
|
||||
else :
|
||||
values['start_amount'] = Decimal('0.0')
|
||||
values['end_amount'] = values['start_amount']
|
||||
|
||||
# add 'checked'-lines to reconciliation
|
||||
lines = Line.search([
|
||||
('date', '>=', reconciliation.date_from),
|
||||
('date', '<=', reconciliation.date_to),
|
||||
('cashbook.id', '=', reconciliation.cashbook.id),
|
||||
('reconciliation', '=', None),
|
||||
('state', 'in', ['check', 'recon']),
|
||||
to_write.extend([
|
||||
[reconciliation],
|
||||
cls.get_values_wfcheck(reconciliation),
|
||||
])
|
||||
if len(lines) > 0:
|
||||
values['lines'] = [('add', [x.id for x in lines])]
|
||||
|
||||
# add amounts of new lines
|
||||
values['end_amount'] += sum([x.credit - x.debit for x in lines])
|
||||
# add amounts of already linked lines
|
||||
values['end_amount'] += sum([x.credit - x.debit for x in reconciliation.lines])
|
||||
|
||||
to_write.extend([[reconciliation], values])
|
||||
|
||||
if len(to_write) > 0:
|
||||
Recon.write(*to_write)
|
||||
|
|
|
@ -23,9 +23,9 @@ full copyright notices and license terms. -->
|
|||
</group>
|
||||
|
||||
<label name="start_amount"/>
|
||||
<field name="start_amount"/>
|
||||
<field name="start_amount" symbol="currency"/>
|
||||
<label name="end_amount"/>
|
||||
<field name="end_amount"/>
|
||||
<field name="end_amount" symbol="currency"/>
|
||||
|
||||
<label name="date"/>
|
||||
<field name="date"/>
|
||||
|
|
Loading…
Reference in a new issue