From cf9de209e37a30b1945a78fbb51425ffca323979 Mon Sep 17 00:00:00 2001 From: Valentin Chevalier Date: Wed, 6 Jul 2022 13:09:15 +0000 Subject: [PATCH] [FIX] sale: only consider paid transactions when confirming orders Before this commit, orders were not confirmed when there was more than one transaction linked to them, regardless of their state. As of now, we check if there is only one confirmed transaction (meaning that the state of the transaction is either 'authorized' or 'done'). Fix 4d2b04a843c27981e44d6f932d7cf7e6838b4b9d task-2906040 closes odoo/odoo#95443 Signed-off-by: Victor Feyens (vfe) --- addons/sale/models/payment_transaction.py | 4 +++- addons/sale/tests/test_payment_flow.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) 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')