From 8bb95f12d74474da5df3dbeac3085a421008d292 Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Fri, 25 Aug 2023 11:17:32 +0200 Subject: [PATCH] [FIX] website_sale: don't update `carrier_id` during GET method Steps to reproduce: ------------------- - create a cart; - select an other shipping method than the default; - apply a coupon code; Issue: ------ The shipping method is modified. Cause: ------ In the `_check_carrier_quotation`, we try to update the carrier id with the partner's preferred carrier. This behavior can be changed using `force_carrier_id` and `keep_carrier` params. When we call this route with a `GET` method, these parameters don't exist. We will update the `carrier_id` according to: ```py if not force_carrier_id and self.partner_shipping_id.property_delivery_carrier_id and not keep_carrier: force_carrier_id = self.partner_shipping_id.property_delivery_carrier_id.id ``` This will have the effect of modifying the `carrier_id` that we have previously modified. Solution: --------- Perform this logic only during a `POST` method. When we call the route with a `GET` method, we only want the information, without modifying it. opw-3457243 closes odoo/odoo#133819 X-original-commit: 94ed203404b3b2121122697f5ebfe09cc21e3630 Signed-off-by: Antoine Vandevenne (anv) Signed-off-by: Thomas Lefebvre (thle) --- addons/website_sale/controllers/main.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 6ec1e7248de..2de1d3732b7 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -1546,14 +1546,17 @@ class WebsiteSale(http.Controller): did go to a payment.provider website but closed the tab without paying / canceling """ - carrier_id = post.get('carrier_id') - keep_carrier = post.get('keep_carrier', False) - if keep_carrier: - keep_carrier = bool(int(keep_carrier)) - if carrier_id: - carrier_id = int(carrier_id) order = request.website.sale_get_order() - if order: + + if order and (request.httprequest.method == 'POST' or not order.carrier_id): + # Update order's carrier_id (will be the one of the partner if not defined) + # If a carrier_id is (re)defined, redirect to "/shop/payment" (GET method to avoid infinite loop) + carrier_id = post.get('carrier_id') + keep_carrier = post.get('keep_carrier', False) + if keep_carrier: + keep_carrier = bool(int(keep_carrier)) + if carrier_id: + carrier_id = int(carrier_id) order._check_carrier_quotation(force_carrier_id=carrier_id, keep_carrier=keep_carrier) if carrier_id: return request.redirect("/shop/payment")