[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 4d2b04a843

task-2906040

closes odoo/odoo#95443

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Valentin Chevalier
2022-07-14 14:10:01 +02:00
parent 8c05baeab7
commit cf9de209e3
2 changed files with 25 additions and 1 deletions
+3 -1
View File
@@ -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()
+22
View File
@@ -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')