From ed586dfc688d70d0d2d6e83abfb5bfc9c2004092 Mon Sep 17 00:00:00 2001 From: "Merlin (megu)" Date: Thu, 12 May 2022 07:58:51 +0000 Subject: [PATCH] [FIX] account: prevent draft entry for reconciled statement Journal entries of a bank statement can be reset to draft even if the bank statement has been validated Steps to reproduce: 1. Install Accounting 2. Go to Accounting dashboard, click on the 3 dots of Bank and go to View > Statements 3. Create a new statement with a transaction of 100, correctly set the ending balance, save and post 4. Click on reconcile then validate the reconciliation 5. Go back to the statement and validate it 6. Open the journal entry of the statement 7. You can reset it to draft but you shouldn't be able to Solution: Prevent the user from resetting a journal entry to draft if the statement has been confirmed opw-2827117 closes odoo/odoo#92713 X-original-commit: 5622bc103e063d62f75625ca413a06aa7395d654 Signed-off-by: Laurent Smet Signed-off-by: Guillaume Merlin (megu) --- .../account/models/account_bank_statement.py | 2 +- .../tests/test_account_bank_statement.py | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 2d238586f47..dc7addc2b83 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -904,7 +904,7 @@ class AccountBankStatementLine(models.Model): st_line_vals_to_write = {} if 'state' in changed_fields: - if (st_line.state == 'open' and move.state != 'draft') or (st_line.state == 'posted' and move.state != 'posted'): + if (st_line.state == 'open' and move.state != 'draft') or (st_line.state in ('posted', 'confirm') and move.state != 'posted'): raise UserError(_( "You can't manually change the state of journal entry %s, as it has been created by bank " "statement %s." diff --git a/addons/account/tests/test_account_bank_statement.py b/addons/account/tests/test_account_bank_statement.py index 21e2fd94b77..6d561152ba1 100644 --- a/addons/account/tests/test_account_bank_statement.py +++ b/addons/account/tests/test_account_bank_statement.py @@ -1141,6 +1141,32 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): {'debit': 0.0, 'credit': 80.0, 'amount_currency': -80.0, 'currency_id': self.currency_1.id}, ) + def test_reconciliation_move_draft(self): + ''' Ensures that the account move of a reconciled statement cannot be set to draft + ''' + statement = self.env['account.bank.statement'].create({ + 'name': 'test_statement', + 'date': '2019-01-01', + 'journal_id': self.bank_journal_1.id, + 'line_ids': [ + (0, 0, { + 'date': '2019-01-01', + 'payment_ref': 'line_1', + 'partner_id': self.partner_a.id, + 'amount': 100.0, + }), + ], + }) + + statement.button_post() + statement.line_ids[0].reconcile([{'name': 'test', 'account_id': self.company_data['default_account_revenue'].id, 'balance': -100}]) + + statement.button_validate_or_action() + account_move = statement.line_ids.move_id + + with self.assertRaises(UserError): + account_move.button_draft() + def test_reconciliation_statement_line_state(self): ''' Test the reconciliation on the bank statement line with a foreign currency on the journal: - Ensure the statement line is_reconciled field is well computed.