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 @@