[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) <thle@odoo.com> Co-authored-by: Feyensv <vfe@odoo.com>
This commit is contained in:
co-authored by
Feyensv
parent
2fde5b47d1
commit
a251b0d15d
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user