|
| 1 | +# Copyright 2025 Akretion (http://www.akretion.com). |
| 2 | +# @author Florian Mounier <[email protected]> |
| 3 | +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
| 4 | + |
| 5 | +from odoo.addons.payment.tests.common import PaymentCommon |
| 6 | + |
| 7 | +from .common import SaleCartCommon |
| 8 | + |
| 9 | + |
| 10 | +class TestSaleCartPayment(SaleCartCommon, PaymentCommon): |
| 11 | + def test_action_confirm_cart_on_transaction_authorized(self): |
| 12 | + self.assertEqual("draft", self.so_cart.state) |
| 13 | + self.assertEqual("cart", self.so_cart.typology) |
| 14 | + transaction = self.env["payment.transaction"].create( |
| 15 | + { |
| 16 | + "amount": self.so_cart.amount_total, |
| 17 | + "currency_id": self.currency.id, |
| 18 | + "provider_id": self.provider.id, |
| 19 | + "reference": self.so_cart.name, |
| 20 | + "operation": "online_redirect", |
| 21 | + "partner_id": self.partner.id, |
| 22 | + } |
| 23 | + ) |
| 24 | + self.so_cart.transaction_ids |= transaction |
| 25 | + self.provider.support_manual_capture = True |
| 26 | + transaction._set_authorized() |
| 27 | + self.assertEqual("sale", self.so_cart.typology) |
| 28 | + # The sale order is confirmed since a transaction with the right amount |
| 29 | + # is authorized |
| 30 | + self.assertEqual("sale", self.so_cart.state) |
| 31 | + |
| 32 | + def test_action_confirm_cart_on_transaction_pending(self): |
| 33 | + self.assertEqual("draft", self.so_cart.state) |
| 34 | + self.assertEqual("cart", self.so_cart.typology) |
| 35 | + transaction = self.env["payment.transaction"].create( |
| 36 | + { |
| 37 | + "amount": self.so_cart.amount_total, |
| 38 | + "currency_id": self.currency.id, |
| 39 | + "provider_id": self.provider.id, |
| 40 | + "reference": self.so_cart.name, |
| 41 | + "operation": "online_redirect", |
| 42 | + "partner_id": self.partner.id, |
| 43 | + } |
| 44 | + ) |
| 45 | + self.so_cart.transaction_ids |= transaction |
| 46 | + transaction._set_pending() |
| 47 | + self.assertEqual("sale", self.so_cart.typology) |
| 48 | + # The sale order is set to 'sent' when a transaction is pending |
| 49 | + self.assertEqual("sent", self.so_cart.state) |
| 50 | + transaction._reconcile_after_done() |
| 51 | + self.assertEqual("sent", self.so_cart.state) |
| 52 | + |
| 53 | + def test_action_confirm_cart_on_transaction_done(self): |
| 54 | + self.assertEqual("draft", self.so_cart.state) |
| 55 | + self.assertEqual("cart", self.so_cart.typology) |
| 56 | + transaction = self.env["payment.transaction"].create( |
| 57 | + { |
| 58 | + "amount": self.so_cart.amount_total, |
| 59 | + "currency_id": self.currency.id, |
| 60 | + "provider_id": self.provider.id, |
| 61 | + "reference": self.so_cart.name, |
| 62 | + "operation": "online_redirect", |
| 63 | + "partner_id": self.partner.id, |
| 64 | + } |
| 65 | + ) |
| 66 | + self.so_cart.transaction_ids |= transaction |
| 67 | + transaction._set_done() |
| 68 | + self.assertEqual("sale", self.so_cart.typology) |
| 69 | + # The sale order is not confirmed instantly on done |
| 70 | + self.assertEqual("draft", self.so_cart.state) |
| 71 | + # The sale order is confirmed after the post-processing |
| 72 | + transaction._reconcile_after_done() |
| 73 | + self.assertEqual("sale", self.so_cart.state) |
| 74 | + |
| 75 | + def test_action_confirm_cart_on_transaction_error(self): |
| 76 | + self.assertEqual("draft", self.so_cart.state) |
| 77 | + self.assertEqual("cart", self.so_cart.typology) |
| 78 | + transaction = self.env["payment.transaction"].create( |
| 79 | + { |
| 80 | + "amount": self.so_cart.amount_total, |
| 81 | + "currency_id": self.currency.id, |
| 82 | + "provider_id": self.provider.id, |
| 83 | + "reference": self.so_cart.name, |
| 84 | + "operation": "online_redirect", |
| 85 | + "partner_id": self.partner.id, |
| 86 | + } |
| 87 | + ) |
| 88 | + self.so_cart.transaction_ids |= transaction |
| 89 | + transaction._set_error(state_message="Test error") |
| 90 | + # The sale order stays as a cart on error |
| 91 | + self.assertEqual("cart", self.so_cart.typology) |
| 92 | + # The sale order is not confirmed on error |
| 93 | + self.assertEqual("draft", self.so_cart.state) |
| 94 | + |
| 95 | + def test_action_confirm_cart_on_transaction_cancel(self): |
| 96 | + self.assertEqual("draft", self.so_cart.state) |
| 97 | + self.assertEqual("cart", self.so_cart.typology) |
| 98 | + transaction = self.env["payment.transaction"].create( |
| 99 | + { |
| 100 | + "amount": self.so_cart.amount_total, |
| 101 | + "currency_id": self.currency.id, |
| 102 | + "provider_id": self.provider.id, |
| 103 | + "reference": self.so_cart.name, |
| 104 | + "operation": "online_redirect", |
| 105 | + "partner_id": self.partner.id, |
| 106 | + } |
| 107 | + ) |
| 108 | + self.so_cart.transaction_ids |= transaction |
| 109 | + transaction._set_canceled() |
| 110 | + # The sale order stays as a cart on cancel |
| 111 | + self.assertEqual("cart", self.so_cart.typology) |
| 112 | + # The sale order is not confirmed on cancel |
| 113 | + self.assertEqual("draft", self.so_cart.state) |
| 114 | + |
| 115 | + def test_action_confirm_cart_on_transaction_authorize_wrong_amount(self): |
| 116 | + self.assertEqual("draft", self.so_cart.state) |
| 117 | + self.assertEqual("cart", self.so_cart.typology) |
| 118 | + transaction = self.env["payment.transaction"].create( |
| 119 | + { |
| 120 | + "amount": self.so_cart.amount_total + 100, # Wrong amount |
| 121 | + "currency_id": self.currency.id, |
| 122 | + "provider_id": self.provider.id, |
| 123 | + "reference": self.so_cart.name, |
| 124 | + "operation": "online_redirect", |
| 125 | + "partner_id": self.partner.id, |
| 126 | + } |
| 127 | + ) |
| 128 | + self.so_cart.transaction_ids |= transaction |
| 129 | + self.provider.support_manual_capture = True |
| 130 | + transaction._set_authorized() |
| 131 | + self.assertEqual("sale", self.so_cart.typology) |
| 132 | + # The sale order is not confirmed since the transaction amount is wrong |
| 133 | + self.assertEqual("draft", self.so_cart.state) |
0 commit comments