[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) <anv@odoo.com>
Signed-off-by: Mahdi Cheikh Rouhou (macr) <macr@odoo.com>
This commit is contained in:
Mahdi Cheikh Rouhou (macr)
2024-01-18 15:12:00 +00:00
parent 2b65959cdc
commit 4a3e8e8281
@@ -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);
}