diff --git a/CHANGELOG b/CHANGELOG index 755023a9ab..c03a62a61c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Mark Payment as succeded when imported in statement + Version 4.0.0 - 2016-05-02 * Bug fixes (see mercurial logs for details) * Add Python3 support @@ -9,4 +11,4 @@ Version 3.6.0 - 2015-04-20 * Bug fixes (see mercurial logs for details) * Add support for PyPy Version 3.4.0 - 2014-10-20 -* Initial release \ No newline at end of file +* Initial release diff --git a/statement.py b/statement.py index d7ed9ea278..9409789c6d 100644 --- a/statement.py +++ b/statement.py @@ -16,9 +16,18 @@ class Statement: def create_move(cls, statements): pool = Pool() MoveLine = pool.get('account.move.line') + Payment = pool.get('account.payment') moves = super(Statement, cls).create_move(statements) + to_success = [] + for move, statement, lines in moves: + for line in lines: + if line.payment: + to_success.append(line.payment) + if to_success: + Payment.succeed(to_success) + for move, statement, lines in moves: assert len({l.payment for l in lines}) == 1 line = lines[0] diff --git a/tests/scenario_account_payment_clearing.rst b/tests/scenario_account_payment_clearing.rst index 5bf56d1cd8..2157bb90f2 100644 --- a/tests/scenario_account_payment_clearing.rst +++ b/tests/scenario_account_payment_clearing.rst @@ -310,3 +310,65 @@ Succeed payment:: Decimal('20.00') >>> debit_line.amount_second_currency Decimal('40.00') + +Validate Statement with processing payment +-------------------------------------------- + +Create a payable move:: + + >>> move = Move() + >>> move.journal = expense + >>> line = move.lines.new(account=payable, party=supplier, + ... credit=Decimal('50.00')) + >>> line = move.lines.new(account=expense, debit=Decimal('50.00')) + >>> move.click('post') + +Create a processing payment for the move:: + + >>> Payment = Model.get('account.payment') + >>> line, = [l for l in move.lines if l.account == payable] + >>> pay_line = Wizard('account.move.line.pay', [line]) + >>> pay_line.form.journal = payment_journal + >>> pay_line.execute('pay') + >>> payment, = Payment.find([('line', '=', line.id)]) + >>> payment.click('approve') + >>> payment.state + u'approved' + >>> process_payment = Wizard('account.payment.process', [payment]) + >>> process_payment.execute('process') + >>> payment.reload() + >>> payment.state + u'processing' + +Create statement for the payment:: + + >>> statement = Statement(name='test', + ... journal=statement_journal, + ... start_balance=Decimal('-50.00'), + ... end_balance=Decimal('-100.00')) + >>> line = statement.lines.new(date=today) + >>> line.payment = payment + >>> line.party == supplier + True + >>> line.account == bank_clearing + True + >>> line.amount + Decimal('-50.00') + >>> statement.save() + +Validate statement and check the payment is confirmed:: + + >>> statement.click('validate_statement') + >>> statement.state + u'validated' + >>> line, = statement.lines + >>> move_line, = [l for l in line.move.lines + ... if l.account == bank_clearing] + >>> bool(move_line.reconciliation) + True + >>> payment.reload() + >>> payment.state + u'succeeded' + >>> debit_line, = [l for l in payment.clearing_move.lines if l.debit > 0] + >>> debit_line.debit + Decimal('50.00')