From 5326804787e9d661c8d3bc1a1d6450dc1254c21f Mon Sep 17 00:00:00 2001 From: "Eteil Djoumatchoua(etdj)" Date: Tue, 29 Aug 2023 10:30:02 +0200 Subject: [PATCH] [FIX] website_sale: Pick the right shipping method on order confirmation Steps to reproduce: - Enable different shipment methods (eg. Fedex US, USPS, DHLS US). - Enable the 'Wire transfer' payment provider. - Go to website, choose a storable product and checkout. - On the last step of checkout, just click on 'Pay' Issue: The delivery method and cost is not the that was initially selected on the checkout page. Reason: On the start of the ``websiteSaleDelivery`` widget, we try to initialize the shipping cost of every shipping methods in the list. But the we make a call on ``/shop/update_carrier`` which not only gives the shipping cost but also change the delivery method of the order. As the loop is async, the last random carrier to be computed is the one on the sale order when validating. So if we don't click on the shipping method we want(to update the carrier) it will that last one which will be used. Solution: Use the ``/shop/carrier_rate_shipment`` which only returns a result with the cost without touching the sale order. opw-3457396 closes odoo/odoo#133846 X-original-commit: 7e2682b903b7908f0e86f66603e34d0b6fe90e52 Signed-off-by: Antoine Vandevenne (anv) Signed-off-by: Eteil Junior Djoumatchoua (etdj) --- .../static/src/js/website_sale_delivery.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/addons/website_sale/static/src/js/website_sale_delivery.js b/addons/website_sale/static/src/js/website_sale_delivery.js index 505c25a062f..0dccb5e5b39 100644 --- a/addons/website_sale/static/src/js/website_sale_delivery.js +++ b/addons/website_sale/static/src/js/website_sale_delivery.js @@ -39,7 +39,7 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({ await this._getCurrentLocation(); await this.carriers.forEach(async (carrierInput) => { this._showLoading((carrierInput)); - await this._handleCarrierUpdateResult(carrierInput) + await this._getCarrierRateShipment(carrierInput); }); if (this._super && typeof(this._super.apply)==="function") { return this._super.apply(this, arguments); @@ -117,6 +117,21 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({ */ _updateShippingCost: function(amount) { core.bus.trigger('update_shipping_cost', amount); + }, + /** + * Get the rate shipment of a carrier + * + * @private + * @params {Object} carrier: The carrier element + */ + _getCarrierRateShipment: async function(carrierInput) { + const result = await this._rpc({ + route: '/shop/carrier_rate_shipment', + params: { + 'carrier_id': carrierInput.value, + } + }); + this._handleCarrierUpdateResultBadge(result); }, /** * @private