From 4d7671a4c355b33aa75a2aa81d3ea84ce164538f Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Mon, 8 Jun 2015 15:55:05 +0200 Subject: [PATCH] [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 --- addons/website_sale/static/src/js/website_sale.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index d48accaac58..e07b59f97cc 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -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;