diff --git a/reconciliation.py b/reconciliation.py index 18b5a60..37da8a8 100644 --- a/reconciliation.py +++ b/reconciliation.py @@ -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) diff --git a/view/recon_form.xml b/view/recon_form.xml index 478fba6..2fe66f4 100644 --- a/view/recon_form.xml +++ b/view/recon_form.xml @@ -23,9 +23,9 @@ full copyright notices and license terms. -->