Bug: Users are able to modify their eCommerce cart after it has been paid when they fail to return to Odoo through the payment provider's return route. This prevents the cart from being confirmed. Steps to reproduce: 1. Install the payment provider Mollie and set it to test mode. 2. Go to the /shop page, add a product to the cart, and select Mollie for the payment. 3. On Mollie's hosted payment page, use the card number 4111111111111111 with the expiry date 03/30 and the secret code 123. Select 'paid' as the payment outcome. 4. Confirm the payment but take care not to be redirected to the /payment/status route. For examples, close the tab before or comment out https://github.com/odoo/odoo/blob/15.0/addons/payment_mollie/controllers/main.py#L38. 5. Go back to /shop/cart and modify the cart. 6. Wait up to 20 minutes for the "payment: post-process transactions" cron to try to confirm the cart. 7. Check the cart's chatter: the confirmation failed because the cart's and transaction's amounts mismatch. Explanation: The post-processing of the transaction is responsible for confirming the cart, but it failed to be triggered because the user did not visit the /payment/status page. The post-processing cron takes care of pending post-processings after 10 to 20 minutes, which is long enough for the user to modify their cart. Fix: Force creating a new cart as soon as the current one is paid and is being requested by the website. task-2995504 closes odoo/odoo#102060 X-original-commit: 5f8674621cbf5919e10e32f29b66ae171fe05993 Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com> Signed-off-by: William Braeckman (wbr) <wbr@odoo.com>
37 lines
1.8 KiB
Python
37 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from unittest.mock import patch
|
|
|
|
from odoo.exceptions import UserError
|
|
from odoo.addons.payment.tests.common import PaymentCommon
|
|
from odoo.addons.website_sale_delivery.controllers.main import WebsiteSaleDelivery
|
|
from odoo.addons.website.tools import MockRequest
|
|
from odoo.tests import tagged
|
|
|
|
@tagged('post_install', '-at_install')
|
|
class TestWebsiteSaleDeliveryController(PaymentCommon):
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.website = self.env.ref('website.default_website')
|
|
self.Controller = WebsiteSaleDelivery()
|
|
|
|
# test that changing the carrier while there is a pending transaction raises an error
|
|
def test_controller_change_carrier_when_transaction(self):
|
|
with MockRequest(self.env, website=self.website):
|
|
order = self.website.sale_get_order(force_create=True)
|
|
order.transaction_ids = self._create_transaction(flow='redirect', state='pending')
|
|
with self.assertRaises(UserError):
|
|
with patch(
|
|
'odoo.addons.website_sale.models.website.Website.sale_get_order',
|
|
return_value=order,
|
|
): # Patch to retrieve the order even if it is linked to a pending transaction.
|
|
self.Controller.update_eshop_carrier(carrier_id=1)
|
|
|
|
# test that changing the carrier while there is a draft transaction doesn't raise an error
|
|
def test_controller_change_carrier_when_draft_transaction(self):
|
|
with MockRequest(self.env, website=self.website):
|
|
order = self.website.sale_get_order(force_create=True)
|
|
order.transaction_ids = self._create_transaction(flow='redirect', state='draft')
|
|
self.Controller.update_eshop_carrier(carrier_id=1)
|