From e7ab65ab6caf3bc86d9255f4d38e3120fc957f50 Mon Sep 17 00:00:00 2001 From: guva-odoo Date: Thu, 28 Mar 2024 15:55:50 +0000 Subject: [PATCH] [FIX] account: payment state reversed payment move Steps: - Create a Customer Invoice CI - Register a full payment P - Create a Bank Transaction BT - Reconcile BT with P - Go to the payment's move and click on "Reverse Entry" button -> First issue: Two buttons ("Reverse" and "Reverse and create invoice") It should be only one ("Reverse") - Click on "Reverse" button -> The invoice is still marked as "paid", it should be "not paid" The reason is that `is_cancel_needed` variable is not well computed in `reverse_moves()` as since 4d3ac4cbd87fa3db2bf7ac21d729a91eaf52a9be, there is no `refund_method` on the reversal wizard, which was used instead of `is_modify` parameter, which is not enough in our case. opw-3772117 closes odoo/odoo#161534 X-original-commit: 5f3c1957b391e3395dbebac4ccb6592af9e4a7dd Signed-off-by: Laurent Smet (las) Signed-off-by: Guillaume Vanleynseele (guva) --- .../tests/test_account_move_in_invoice.py | 4 +-- addons/account/tests/test_account_payment.py | 25 +++++++++++++++++++ .../account/wizard/account_move_reversal.py | 2 +- .../wizard/account_move_reversal_view.xml | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py index f5cd4d62265..362ff08caa1 100644 --- a/addons/account/tests/test_account_move_in_invoice.py +++ b/addons/account/tests/test_account_move_in_invoice.py @@ -2407,8 +2407,8 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): Command.update(line.id, {'balance': amount}), ], }) - - reverse_move.action_post() + if reverse_move.state == 'draft': + reverse_move.action_post() def create_statement_line(move, amount): statement_line = self.env['account.bank.statement.line'].create({ diff --git a/addons/account/tests/test_account_payment.py b/addons/account/tests/test_account_payment.py index 9f47a53d4b5..9249eedc2a4 100644 --- a/addons/account/tests/test_account_payment.py +++ b/addons/account/tests/test_account_payment.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from odoo import Command from odoo.addons.account.tests.common import AccountTestInvoicingCommon from odoo.tests import tagged, new_test_user from odoo.tests.common import Form @@ -859,6 +860,30 @@ class TestAccountPayment(AccountTestInvoicingCommon): 'is_matched': True, }]) + def test_reconciliation_payment_states_reverse_payment_move(self): + invoice = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': self.partner_a.id, + 'invoice_line_ids': [Command.create({'product_id': self.product_a.id})], + }) + invoice.action_post() + + payment = self.env['account.payment.register']\ + .with_context(active_model='account.move', active_ids=invoice.ids)\ + .create({})\ + ._create_payments() + + self.assertTrue(invoice.payment_state in ('paid', 'in_payment')) + self.assertRecordValues(payment, [{'reconciled_invoice_ids': invoice.ids}]) + + # Reverse the payment move + reversal_wizard = self.env['account.move.reversal']\ + .with_context(active_model='account.move', active_ids=payment.move_id.ids)\ + .create({'reason': "oopsie", 'journal_id': payment.journal_id.id}) + reversal_wizard.refund_moves() + self.assertRecordValues(invoice, [{'payment_state': 'not_paid'}]) + self.assertRecordValues(payment.line_ids, [{'reconciled': True}] * 2) + def test_payment_name(self): AccountPayment = self.env['account.payment'] AccountPayment.search([]).unlink() diff --git a/addons/account/wizard/account_move_reversal.py b/addons/account/wizard/account_move_reversal.py index 0306b567c54..4e7af6a8776 100644 --- a/addons/account/wizard/account_move_reversal.py +++ b/addons/account/wizard/account_move_reversal.py @@ -118,7 +118,7 @@ class AccountMoveReversal(models.TransientModel): ] for move, default_vals in zip(moves, default_values_list): is_auto_post = default_vals.get('auto_post') != 'no' - is_cancel_needed = not is_auto_post and is_modify + is_cancel_needed = not is_auto_post and (is_modify or self.move_type == 'entry') batch_index = 0 if is_cancel_needed else 1 batches[batch_index][0] |= move batches[batch_index][1].append(default_vals) diff --git a/addons/account/wizard/account_move_reversal_view.xml b/addons/account/wizard/account_move_reversal_view.xml index 8bdc473539c..2ca91a33216 100644 --- a/addons/account/wizard/account_move_reversal_view.xml +++ b/addons/account/wizard/account_move_reversal_view.xml @@ -18,7 +18,7 @@