[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) <anv@odoo.com>
Signed-off-by: Thomas Lefebvre (thle) <thle@odoo.com>
This commit is contained in:
Thomas Lefebvre (thle)
2023-09-01 08:27:41 +00:00
parent 6e49301329
commit 8bb95f12d7
+10 -7
View File
@@ -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")