From 4a3e8e8281ad02d5bdc17b559b453025bc85b046 Mon Sep 17 00:00:00 2001 From: "Mahdi Cheikh Rouhou (macr)" Date: Fri, 12 Jan 2024 11:57:10 +0100 Subject: [PATCH] [FIX] website_sale: show payment method on change delivery Issue: ====== Payment methods doesn't show when updating delivery method Steps to reproduce the issue: ============================= - Install website_sale - Activate coupons and promotions in settings - Create a coupon program with the follwing values : reward: discount, percentage: 100% - Save the program and generate some coupons - Activate at least 1 free delivery method and 1 free delivery method - Activate at least one payment method - Go to shop add anything to cart - Apply one of the codes from the generated coupons - Go to confirm order and change between the delivery methods. - If the default delivery method is free, the payment methods will never show , otherwise they will always show. Origin of the issue: ==================== The payment methods were rendered using `t-if` directive which means that we can't toggle it dynamically since they don't exist in the view. Solution: ========= we reload the page only when we toggle from zero to non zero total. opw-3662606 closes odoo/odoo#148431 closes odoo/odoo#149487 closes odoo/odoo#149909 X-original-commit: c88eaa301544d470088d5295028910364ebb34cf Signed-off-by: Antoine Vandevenne (anv) Signed-off-by: Mahdi Cheikh Rouhou (macr) --- .../website_sale/static/src/js/website_sale_delivery.js | 8 ++++++++ 1 file changed, 8 insertions(+) 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 53cd0b383ff..17858c6cb20 100644 --- a/addons/website_sale/static/src/js/website_sale_delivery.js +++ b/addons/website_sale/static/src/js/website_sale_delivery.js @@ -155,6 +155,14 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({ // we need to check if it's the carrier that is selected if (result.new_amount_total_raw !== undefined) { this._updateShippingCost(result.new_amount_total_raw); + // reload page only when amount_total switches between zero and not zero + const hasPaymentMethod = document.querySelector( + "div[name='o_website_sale_free_cart']" + ) === null; + const shouldDisplayPaymentMethod = result.new_amount_total_raw !== 0; + if (hasPaymentMethod !== shouldDisplayPaymentMethod) { + location.reload(false); + } } this._updateShippingCost(result.new_amount_delivery); }