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