[IMP] website_sale: Skip overload with requests

Until the request to get the unit price is not finished, no request is sent to the server.

issue #4298
This commit is contained in:
Goffin Simon 2015-06-08 15:55:05 +02:00
parent 78420d1cf2
commit 4d7671a4c3
1 changed files with 13 additions and 2 deletions

View File

@ -41,10 +41,14 @@ $('.oe_website_sale').each(function () {
$(ev.currentTarget).parents(".thumbnail").toggleClass("disabled");
});
$(oe_website_sale).on("change", ".oe_cart input.js_quantity", function (event) {
$(oe_website_sale).find(".oe_cart input.js_quantity").on("change", function () {
var $input = $(this);
if ($input.data('update_change')) {
console.log($input.val()+ "+++");
return;
}
var value = parseInt($input.val(), 10);
var $dom = $(event.target).closest('tr');
var $dom = $(this).closest('tr');
var default_price = parseFloat($dom.find('.text-danger > span.oe_currency_value').text());
var $dom_optional = $dom.nextUntil(':not(.optional_product.info)');
var line_id = parseInt($input.data('line-id'),10);
@ -54,6 +58,7 @@ $('.oe_website_sale').each(function () {
product_ids.push($(this).find('span[data-product-id]').data('product-id'));
});
if (isNaN(value)) value = 0;
$input.data('update_change', true);
openerp.jsonRpc("/shop/get_unit_price", 'call', {
'product_ids': product_ids,
'add_qty': value,
@ -74,6 +79,12 @@ $('.oe_website_sale').each(function () {
'product_id': parseInt($input.data('product-id'),10),
'set_qty': value})
.then(function (data) {
$input.data('update_change', false);
if (value !== parseInt($input.val(), 10)) {
console.log($input.val()+ "***");
$input.trigger('change');
return;
}
if (!data.quantity) {
location.reload();
return;