From a251b0d15d954932ea43800db6e31c41f61535aa Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Wed, 3 May 2023 07:21:33 +0000 Subject: [PATCH] [FIX] website_sale, website_sale_loyalty: update all total prices Steps to reproduce: - install website_sale; - install a delivery mode (or create it); - add a cost to it; - publish the shipping method; - make the purchase flow and modify the shipping method. Issue: The total price is not updated. Cause: `querySelector` returns the first element that matches one or more selectors. In this case, it is not the one that is expected. Solution: Use `querySelectorAll` to update the price of all items designated by the selector. Remark: An other problem appears with the fix of the first problem when using a gift card to pay (for example). Indeed, the latter did not appear as we did not update the prices correctly. By updating the programs and rewards, the amounts have been recalculated on the sale order. It is necessary to transmit this information to the frontend. opw-3277204 closes odoo/odoo#120744 X-original-commit: 460f90a59218202c1f77405609fadfc2640b2f9c Signed-off-by: Lefebvre Thomas (thle) Co-authored-by: Feyensv --- .../static/src/js/website_sale_delivery.js | 4 +- .../controllers/delivery.py | 38 ++++++++----------- 2 files changed, 17 insertions(+), 25 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 79889b5490e..29f9b2c96d4 100644 --- a/addons/website_sale/static/src/js/website_sale_delivery.js +++ b/addons/website_sale/static/src/js/website_sale_delivery.js @@ -135,12 +135,12 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({ var amountDelivery = document.querySelector('#order_delivery .monetary_field'); var amountUntaxed = document.querySelector('#order_total_untaxed .monetary_field'); var amountTax = document.querySelector('#order_total_taxes .monetary_field'); - var amountTotal = document.querySelector('#order_total .monetary_field, #amount_total_summary.monetary_field'); + var amountTotal = document.querySelectorAll('#order_total .monetary_field, #amount_total_summary.monetary_field'); amountDelivery.innerHTML = result.new_amount_delivery; amountUntaxed.innerHTML = result.new_amount_untaxed; amountTax.innerHTML = result.new_amount_tax; - amountTotal.innerHTML = result.new_amount_total; + amountTotal.forEach(total => total.innerHTML = result.new_amount_total); // 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); diff --git a/addons/website_sale_loyalty/controllers/delivery.py b/addons/website_sale_loyalty/controllers/delivery.py index 7f3ad2344fd..ec13f334f66 100644 --- a/addons/website_sale_loyalty/controllers/delivery.py +++ b/addons/website_sale_loyalty/controllers/delivery.py @@ -1,37 +1,29 @@ -# -*- coding: utf-8 -*- -from odoo import http +# Part of Odoo. See LICENSE file for full copyright and licensing details. + from odoo.addons.website_sale.controllers.delivery import WebsiteSaleDelivery -from odoo.http import request +from odoo.http import request, route class WebsiteSaleLoyaltyDelivery(WebsiteSaleDelivery): - @http.route() - def update_eshop_carrier(self, **post): - Monetary = request.env['ir.qweb.field.monetary'] - result = super().update_eshop_carrier(**post) - order = request.website.sale_get_order() - free_shipping_lines = None - + def _update_website_sale_delivery_return(self, order, **post): if order: order._update_programs_and_rewards() order.validate_taxes_on_sales_order() + result = super()._update_website_sale_delivery_return(order, **post) + if order: free_shipping_lines = order._get_free_shipping_lines() - - if free_shipping_lines: - currency = order.currency_id - amount_free_shipping = sum(free_shipping_lines.mapped('price_subtotal')) - result.update({ - 'new_amount_delivery': Monetary.value_to_html(0.0, {'display_currency': currency}), - 'new_amount_untaxed': Monetary.value_to_html(order.amount_untaxed, {'display_currency': currency}), - 'new_amount_tax': Monetary.value_to_html(order.amount_tax, {'display_currency': currency}), - 'new_amount_total': Monetary.value_to_html(order.amount_total, {'display_currency': currency}), - 'new_amount_order_discounted': Monetary.value_to_html(order.reward_amount - amount_free_shipping, {'display_currency': currency}), - 'new_amount_total_raw': order.amount_total, - }) + if free_shipping_lines: + Monetary = request.env['ir.qweb.field.monetary'] + currency = order.currency_id + amount_free_shipping = sum(free_shipping_lines.mapped('price_subtotal')) + result.update({ + 'new_amount_delivery': Monetary.value_to_html(0.0, {'display_currency': currency}), + 'new_amount_order_discounted': Monetary.value_to_html(order.reward_amount - amount_free_shipping, {'display_currency': currency}), + }) return result - @http.route() + @route() def cart_carrier_rate_shipment(self, carrier_id, **kw): Monetary = request.env['ir.qweb.field.monetary'] order = request.website.sale_get_order(force_create=True)