From 6ae9c9c2f1a43966aa8e2bd3dfd96bcb7d163c66 Mon Sep 17 00:00:00 2001 From: "Mahdi Cheikh Rouhou (macr)" Date: Thu, 16 Nov 2023 11:36:55 +0000 Subject: [PATCH] [FIX] website_sale: show pickup locations if case of 1 shipping method Issue: ====== When we have 1 delivery method enabled that have pickup locations, it will be selected by default and the pickup locations will never be displayed. Steps to reproduce the issue: ============================= - Set up pickup locations carried for sendcloud (like mondial relay) - Go through the website with just that shipping method available and add a product to cart valid with the configuration of sendcloud. - Go to checkoutout you will get the shipping method selected but no pick up options Origin of the issue: ==================== If the delivery method is already selected it will skip showing pickup locations. Solutions: ========== Now there is another check to make sure that it will be skipped only when the pick up locations are displayed. opw-3569497 closes odoo/odoo#142958 X-original-commit: 7beb8767cd82f2938ffbb53ec496e1f817af8730 Signed-off-by: Steve Van Essche Signed-off-by: Mahdi Cheikh Rouhou (macr) --- .../static/src/js/website_sale_delivery.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 12246e1ea29..af9b1f66722 100644 --- a/addons/website_sale/static/src/js/website_sale_delivery.js +++ b/addons/website_sale/static/src/js/website_sale_delivery.js @@ -300,6 +300,16 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({ return true; }, + _isPickupLocationSelected: function (ev) { + return !ev.currentTarget.closest('.o_delivery_carrier_select').querySelector(".o_order_location").parentElement.classList.contains("d-none"); + }, + + _shouldDisplayPickupLocations: function (ev) { + const pickupPointsAreNeeded = ev.currentTarget.querySelector('.o_show_pickup_locations'); + const pickupPointsAreDisplayed = ev.currentTarget.querySelector('.o_list_pickup_locations')?.hasChildNodes(); + return pickupPointsAreNeeded && !pickupPointsAreDisplayed && !this._isPickupLocationSelected(ev); + }, + //-------------------------------------------------------------------------- // Handlers //-------------------------------------------------------------------------- @@ -324,7 +334,7 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({ */ _onClickShowLocations: async function (ev) { // This checks if there is a pick up point already select with that carrier - if (!ev.currentTarget.closest('.o_delivery_carrier_select').querySelector(".o_order_location").parentElement.classList.contains("d-none")) { + if (this._isPickupLocationSelected(ev)) { return; } const showPickupLocations = ev.currentTarget.closest('.o_delivery_carrier_select').querySelector('.o_show_pickup_locations'); @@ -373,7 +383,7 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({ _onCarrierClick: async function (ev) { this._disablePayButton(); const radio = ev.currentTarget.closest('.o_delivery_carrier_select').querySelector('input[type="radio"]'); - if (radio.checked) { + if (radio.checked && !this._shouldDisplayPickupLocations(ev)) { return; } this._showLoading(radio);