From 2d91575b1174bb8492e6a637d97d09d25d376cba Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Wed, 13 Jul 2016 09:29:49 +0200 Subject: [PATCH] [FIX] account: cancelling a bank statement line linked to a payment SEPA or batch deposit should set it back to 'sent' state, not 'posted'. --- addons/account/models/account_bank_statement.py | 2 +- addons/account/models/account_payment.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index b351c53ef71..f0888eae561 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -442,7 +442,7 @@ class AccountBankStatementLine(models.Model): moves_to_cancel.unlink() if payment_to_unreconcile: - payment_to_unreconcile.write({'state': 'posted'}) + payment_to_unreconcile.unreconcile() #################################################### # Reconciliation interface methods diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 37c502a419d..b428815a00c 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -290,6 +290,17 @@ class account_payment(models.Model): def button_dummy(self): return True + @api.multi + def unreconcile(self): + """ Set back the payments in 'posted' or 'sent' state, without deleting the journal entries. + Called when cancelling a bank statement line linked to a pre-registered payment. + """ + for payment in self: + if payment.payment_reference: + payment.write({'state': 'sent'}) + else: + payment.write({'state': 'posted'}) + @api.multi def cancel(self): for rec in self: