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);