Skip to content
Snippets Groups Projects
Commit 43ebcdeb authored by Victor Feyens's avatar Victor Feyens
Browse files

[FIX] sale_management: reload page on option add


Partial revert of 0beebad0

Since the aforementioned commit, if a client updated its order on the portal:
* adding optional products
* removing optional products
* updating optional line quantities
and paid directly after, without reloading the page, the amount he paid
was the amount of the SO when the page was loaded.

Avoiding the reload and only modifying some DOM parts was a bad idea to begin
with.

We'll consider developing a correct and clean way to (re)render the payment part
of the DOM, or use separate pages for orders modifications and effective payment
checkout.

closes odoo/odoo#104925

Signed-off-by: default avatarVictor Feyens (vfe) <vfe@odoo.com>
parent de9a5f85
Branches
Tags
No related merge requests found
......@@ -12,28 +12,6 @@ from odoo.addons.sale.controllers import portal
class CustomerPortal(portal.CustomerPortal):
def _get_portal_order_details(self, order_sudo, order_line=False):
currency = order_sudo.currency_id
format_price = partial(formatLang, request.env, digits=currency.decimal_places)
results = {
'order_amount_total': format_price(order_sudo.amount_total),
'order_amount_untaxed': format_price(order_sudo.amount_untaxed),
'order_amount_tax': format_price(order_sudo.amount_tax),
'order_amount_undiscounted': format_price(order_sudo.amount_undiscounted),
}
if order_line:
results.update({
'order_line_product_uom_qty': str(order_line.product_uom_qty),
'order_line_price_total': format_price(order_line.price_total),
'order_line_price_subtotal': format_price(order_line.price_subtotal)
})
try:
results['order_totals_table'] = request.env['ir.ui.view']._render_template('sale.sale_order_portal_content_totals_table', {'sale_order': order_sudo})
except ValueError:
pass
return results
@http.route(['/my/orders/<int:order_id>/update_line_dict'], type='json', auth="public", website=True)
def update_line_dict(self, line_id, remove=False, unlink=False, order_id=None, access_token=None, input_quantity=False, **kwargs):
try:
......@@ -55,20 +33,9 @@ class CustomerPortal(portal.CustomerPortal):
if unlink or quantity <= 0:
order_line.unlink()
results = self._get_portal_order_details(order_sudo)
results.update({
'unlink': True,
'sale_template': request.env['ir.ui.view']._render_template('sale.sale_order_portal_content', {
'sale_order': order_sudo,
'report_type': "html"
}),
})
return results
return
order_line.write({'product_uom_qty': quantity})
results = self._get_portal_order_details(order_sudo, order_line)
return results
@http.route(["/my/orders/<int:order_id>/add_option/<int:option_id>"], type='json', auth="public", website=True)
def add(self, order_id, option_id, access_token=None, **post):
......@@ -83,9 +50,3 @@ class CustomerPortal(portal.CustomerPortal):
return request.redirect(order_sudo.get_portal_url())
option_sudo.add_option_to_order()
results = self._get_portal_order_details(order_sudo)
results['sale_template'] = request.env['ir.ui.view']._render_template("sale.sale_order_portal_content", {
'sale_order': option_sudo.order_id,
'report_type': "html"
})
return results
......@@ -16,7 +16,6 @@ publicWidget.registry.SaleUpdateLineButton = publicWidget.Widget.extend({
async start() {
await this._super(...arguments);
this.orderDetail = this.$el.find('table#sales_order_table').data();
this.elems = this._getUpdatableElements();
},
/**
* Process the change in line quantity
......@@ -54,13 +53,7 @@ publicWidget.registry.SaleUpdateLineButton = publicWidget.Widget.extend({
'unlink': $target.data('unlink'),
'access_token': self.orderDetail.token
}).then((data) => {
var $saleTemplate = $(data['sale_template']);
if ($saleTemplate.length && data['unlink']) {
self.$('#portal_sale_content').html($saleTemplate);
self.elems = self._getUpdatableElements();
}
self._updateOrderLineValues($target.closest('tr'), data);
self._updateOrderValues(data);
window.location.reload()
});
},
/**
......@@ -80,11 +73,7 @@ publicWidget.registry.SaleUpdateLineButton = publicWidget.Widget.extend({
route: "/my/orders/" + self.orderDetail.orderId + "/add_option/" + $target.data('optionId'),
params: {access_token: self.orderDetail.token}
}).then((data) => {
if (data) {
self.$('#portal_sale_content').html($(data['sale_template']));
self.elems = self._getUpdatableElements();
self._updateOrderValues(data);
}
window.location.reload();
});
},
/**
......@@ -102,81 +91,5 @@ publicWidget.registry.SaleUpdateLineButton = publicWidget.Widget.extend({
params: params,
});
},
/**
* Processes data from the server to update the orderline UI
*
* @private
* @param {Element} $orderLine: orderline element to update
* @param {Object} data: contains order and line updated values
*/
_updateOrderLineValues($orderLine, data) {
let linePriceTotal = data.order_line_price_total,
linePriceSubTotal = data.order_line_price_subtotal,
$linePriceTotal = $orderLine.find('.oe_order_line_price_total .oe_currency_value'),
$linePriceSubTotal = $orderLine.find('.oe_order_line_price_subtotal .oe_currency_value');
if (!$linePriceTotal.length && !$linePriceSubTotal.length) {
$linePriceTotal = $linePriceSubTotal = $orderLine.find('.oe_currency_value').last();
}
$orderLine.find('.js_quantity').val(data.order_line_product_uom_qty);
if ($linePriceTotal.length && linePriceTotal !== undefined) {
$linePriceTotal.text(linePriceTotal);
}
if ($linePriceSubTotal.length && linePriceSubTotal !== undefined) {
$linePriceSubTotal.text(linePriceSubTotal);
}
},
/**
* Processes data from the server to update the UI
*
* @private
* @param {Object} data: contains order and line updated values
*/
_updateOrderValues(data) {
let orderAmountTotal = data.order_amount_total,
orderAmountUntaxed = data.order_amount_untaxed,
orderAmountUndiscounted = data.order_amount_undiscounted,
$orderTotalsTable = $(data.order_totals_table);
if (orderAmountUntaxed !== undefined) {
this.elems.$orderAmountUntaxed.text(orderAmountUntaxed);
}
if (orderAmountTotal !== undefined) {
this.elems.$orderAmountTotal.text(orderAmountTotal);
}
if (orderAmountUndiscounted !== undefined) {
this.elems.$orderAmountUndiscounted.text(orderAmountUndiscounted);
}
if ($orderTotalsTable.length) {
this.elems.$orderTotalsTable.find('table').replaceWith($orderTotalsTable);
}
},
/**
* Locate in the DOM the elements to update
* Mostly for compatibility, when the module has not been upgraded
* In that case, we need to fall back to some other elements
*
* @private
* @return {Object}: Jquery elements to update
*/
_getUpdatableElements() {
let $orderAmountUntaxed = $('[data-id="total_untaxed"]').find('span, b'),
$orderAmountTotal = $('[data-id="total_amount"]').find('span, b'),
$orderAmountUndiscounted = $('[data-id="amount_undiscounted"]').find('span, b');
if (!$orderAmountUntaxed.length) {
$orderAmountUntaxed = $orderAmountTotal.eq(1);
$orderAmountTotal = $orderAmountTotal.eq(0).add($orderAmountTotal.eq(2));
}
return {
$orderAmountUntaxed: $orderAmountUntaxed,
$orderAmountTotal: $orderAmountTotal,
$orderTotalsTable: $('#total'),
$orderAmountUndiscounted: $orderAmountUndiscounted,
};
}
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment