diff --git a/addons/sale/models/payment_transaction.py b/addons/sale/models/payment_transaction.py index f65d3584be7..6567b9ede01 100644 --- a/addons/sale/models/payment_transaction.py +++ b/addons/sale/models/payment_transaction.py @@ -175,7 +175,7 @@ class PaymentTransaction(models.Model): confirmed_orders._force_lines_to_invoice_policy_order() invoices = confirmed_orders.with_context( raise_if_nothing_to_invoice=False - )._create_invoices() + )._create_invoices(final=True) # Setup access token in advance to avoid serialization failure between # edi postprocessing of invoice and displaying the sale order on the portal for invoice in invoices: diff --git a/addons/sale/tests/test_payment_flow.py b/addons/sale/tests/test_payment_flow.py index b8411017a4d..c36a1043cac 100644 --- a/addons/sale/tests/test_payment_flow.py +++ b/addons/sale/tests/test_payment_flow.py @@ -259,3 +259,20 @@ class TestSalePayment(AccountPaymentCommon, SaleCommon, PaymentHttpCommon): self.assertTrue(tx.invoice_ids) self.assertTrue(self.sale_order.invoice_ids) + + def test_invoice_is_final(self): + """Test that invoice generated from a payment are always final""" + # Set automatic invoice + self.env['ir.config_parameter'].sudo().set_param('sale.automatic_invoice', 'True') + + # Create the payment + self.amount = self.sale_order.amount_total + tx = self._create_transaction( + flow='redirect', sale_order_ids=[self.sale_order.id], state='done' + ) + with mute_logger('odoo.addons.sale.models.payment_transaction'), patch( + 'odoo.addons.sale.models.sale_order.SaleOrder._create_invoices' + ) as _create_invoices_mock: + tx._reconcile_after_done() + + self.assertTrue(_create_invoices_mock.call_args.kwargs['final'])