From 5d774f42219d18cde96d79d1130bfab8d6ad3bd8 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Tue, 14 Jun 2016 17:10:22 +0200 Subject: [PATCH] [FIX] account: statement line reconciliation cancel Cancelling a statement line should not remove the according journal items if they are associated to an `account.payment`. In this case, this should simply remove the `statement_id` of the move lines, and unmark the `account.payment` as reconciled. opw-674896 --- .../account/models/account_bank_statement.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 04ca1228824..367fbc13800 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -419,17 +419,21 @@ class AccountBankStatementLine(models.Model): @api.multi def button_cancel_reconciliation(self): - # TOCKECK : might not behave as expected in case of reconciliations (match statement line with already - # registered payment) or partial reconciliations : it will completely remove the existing payment. - move_recs = self.env['account.move'] + moves_to_unbind = self.env['account.move'] + moves_to_cancel = self.env['account.move'] for st_line in self: - move_recs = (move_recs | st_line.journal_entry_ids) - if move_recs: - for move in move_recs: + moves_to_unbind |= st_line.journal_entry_ids + for move in st_line.journal_entry_ids: + if any(line.payment_id for line in move.line_ids): + continue + moves_to_cancel |= st_line.journal_entry_ids + if moves_to_unbind: + moves_to_unbind.write({'statement_line_id': False}) + if moves_to_cancel: + for move in moves_to_cancel: move.line_ids.remove_move_reconcile() - move_recs.write({'statement_line_id': False}) - move_recs.button_cancel() - move_recs.unlink() + moves_to_cancel.button_cancel() + moves_to_cancel.unlink() #################################################### # Reconciliation interface methods