diff --git a/addons/sale/models/payment_transaction.py b/addons/sale/models/payment_transaction.py index b770cb15c0f..aafbabb3dda 100644 --- a/addons/sale/models/payment_transaction.py +++ b/addons/sale/models/payment_transaction.py @@ -61,7 +61,9 @@ class PaymentTransaction(models.Model): # vice versa. if len(tx.sale_order_ids) == 1: quotation = tx.sale_order_ids.filtered(lambda so: so.state in ('draft', 'sent')) - if quotation and len(quotation.transaction_ids) == 1: + if quotation and len(quotation.transaction_ids.filtered( + lambda tx: tx.state in ('authorized', 'done') # Only consider confirmed tx + )) == 1: # Check if the SO is fully paid if quotation.currency_id.compare_amounts(tx.amount, quotation.amount_total) == 0: quotation.with_context(send_email=True).action_confirm() diff --git a/addons/sale/tests/test_payment_flow.py b/addons/sale/tests/test_payment_flow.py index 01c3dc0a946..6d11b1b72f9 100644 --- a/addons/sale/tests/test_payment_flow.py +++ b/addons/sale/tests/test_payment_flow.py @@ -197,6 +197,28 @@ class TestSalePayment(PaymentHttpCommon): self.assertEqual(self.order.state, 'draft', 'a partial transaction with automatic invoice and invoice_policy = delivery should not validate a quote') + def test_confirmed_transactions_comfirms_so_with_multiple_transaction(self): + """ Test that a confirmed transaction confirms a SO even if one or more non-confirmed + transactions are linked. """ + # Create the payment + self.amount = self.order.amount_total + self._create_transaction( + flow='redirect', + sale_order_ids=[self.order.id], + state='draft', + reference='Test Transaction Draft 1', + ) + self._create_transaction( + flow='redirect', + sale_order_ids=[self.order.id], + state='draft', + reference='Test Transaction Draft 2', + ) + tx = self._create_transaction(flow='redirect', sale_order_ids=[self.order.id], state='done') + tx._reconcile_after_done() + + self.assertEqual(self.order.state, 'sale') + def test_auto_confirm_and_auto_invoice(self): # Set automatic invoice self.env['ir.config_parameter'].sudo().set_param('sale.automatic_invoice', 'True')