From 2eb9c0708f89bc796e45fd5947ffe097d4c8c4be Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Fri, 9 Jun 2023 09:19:05 +0000 Subject: [PATCH] [FIX] website_sale: manage access_point_address with Sendcloud Steps to reproduce: ------------------- - install website_sale and delivery_sendcloud module; - create a shipping method (use Sendcloud provider); - configure the integration with "Mondial Relay Point Relais International 1-2kg"; - configure option with shipping rule and use location; - on website create a new quotation with the pubic user; - process the checkout; (Check in backend the shipping weight) - fill City and Zip Code fields with correct value (example: Paris | 75011) (- configure the company's country) Issue: ------ [1.] If the shipping method is the only one, the locations are not displayed. [2.] The delivery address is not the address of the chosen location. Cause: ------ [2.] The method `update_eshop_carrier` is retriggered after update the `access_point_address` field. The `access_point_address` is reset. Solution: --------- [1.] Show the option to choose a location if we only have one delivery method (we are certain that the options should be displayed). [2.] Use a parameter in the post request to instruct not to reset the `access_point_address` field. opw-3326139 closes odoo/odoo#125647 X-original-commit: 677bff31d3acdd05fff6567b693de78cff256ea2 Signed-off-by: Lefebvre Thomas (thle) Signed-off-by: William Henrotin (whe) --- addons/website_sale/controllers/delivery.py | 3 ++- .../static/src/js/website_sale_delivery.js | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/addons/website_sale/controllers/delivery.py b/addons/website_sale/controllers/delivery.py index 2ab0c5090cd..5d0221b9c72 100644 --- a/addons/website_sale/controllers/delivery.py +++ b/addons/website_sale/controllers/delivery.py @@ -15,7 +15,8 @@ class WebsiteSaleDelivery(WebsiteSale): @http.route(['/shop/update_carrier'], type='json', auth='public', methods=['POST'], website=True) def update_eshop_carrier(self, **post): order = request.website.sale_get_order() - order.access_point_address = {} + if not post.get('no_reset_access_point_address'): + order.access_point_address = {} carrier_id = int(post['carrier_id']) if order and carrier_id != order.carrier_id.id: if any(tx.sudo().state not in ('cancel', 'error', 'draft') for tx in order.transaction_ids): 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 29f9b2c96d4..e16c429ded1 100644 --- a/addons/website_sale/static/src/js/website_sale_delivery.js +++ b/addons/website_sale/static/src/js/website_sale_delivery.js @@ -22,13 +22,13 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({ * @override */ start: async function () { - const carriers = Array.from(document.querySelectorAll('input[name="delivery_type"]')); + this.carriers = Array.from(document.querySelectorAll('input[name="delivery_type"]')); this.dp = new concurrency.DropPrevious(); // Workaround to: // - update the amount/error on the label at first rendering // - prevent clicking on 'Pay Now' if the shipper rating fails - if (carriers.length > 0) { - const carrierChecked = carriers.filter(e =>e.checked) + if (this.carriers.length > 0) { + const carrierChecked = this.carriers.filter(e =>e.checked) if (carrierChecked.length === 0) { const payButton = document.querySelector('button[name="o_payment_submit_button"]'); payButton? payButton.disabled = true : null; @@ -38,7 +38,7 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({ } await this._getCurrentLocation(); - await carriers.forEach(async (carrierInput) => { + await this.carriers.forEach(async (carrierInput) => { this._showLoading((carrierInput)); await this._handleCarrierUpdateResult(carrierInput) }); @@ -92,7 +92,7 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({ } const currentCarrierChecked = docCarrier.closest("li").getElementsByTagName("input")[0].checked; const span = document.createElement("em"); - if (!currentCarrierChecked) { + if (!currentCarrierChecked || this.carriers.length == 1) { span.textContent = "select to see available Pick-Up Locations"; span.classList.add("text-muted"); } @@ -389,6 +389,7 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({ route: '/shop/update_carrier', params: { 'carrier_id': carrierId, + 'no_reset_access_point_address': true, }, }) this._setIsPayable(result.status)