From 22d31817deaf5702adb8d255a2c09d4dfaa4a8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Thu, 28 Nov 2013 09:16:51 +0100 Subject: [PATCH] made getVATRates synchronous to avoid concurrency problems --- htdocs/core/tpl/objectline_add.tpl.php | 33 ++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/htdocs/core/tpl/objectline_add.tpl.php b/htdocs/core/tpl/objectline_add.tpl.php index 6e1c3c687f9..92f965ad968 100644 --- a/htdocs/core/tpl/objectline_add.tpl.php +++ b/htdocs/core/tpl/objectline_add.tpl.php @@ -242,7 +242,6 @@ $(document).ready(function() { $('#service_duration_area').hide(); $('#idprod').change(function() { - if ($(this).val() > 0) { // Update vat rate combobox @@ -260,11 +259,11 @@ $(document).ready(function() { if (typeof data != 'undefined') { $('#product_ref').val(data.ref); $('#product_label').val(data.label); + $('#origin_tva_tx_cache').val(data.tva_tx); $('#price_base_type').val(data.pricebasetype).trigger('change'); $('#price_ht').val(data.price_ht).trigger('change'); $('#origin_price_ht_cache').val(data.price_ht); //$('#origin_price_ttc_cache').val(data.price_ttc); - $('#origin_tva_tx_cache').val(data.tva_tx); $('#select_type').val(data.type).attr('disabled','disabled').trigger('change'); //$('#price_base_type_area').show(); $('#qty').val(data.qty); @@ -283,9 +282,6 @@ $(document).ready(function() { $('#price_ttc').val(''); - // Restore vat rate combobox - getVATRates('getSellerVATRates', 'tva_tx'); - // For compatibility with combobox global->PRODUIT_USE_SEARCH_TO_SELECT)) { ?> $('#select_type').val('').removeAttr('disabled').trigger('change'); @@ -461,16 +457,23 @@ $(document).ready(function() { function getVATRates(action, htmlname, idprod) { var productid = (idprod?idprod:0); - $.post('/core/ajax/vatrates.php', { - 'action': action, - 'id': id; ?>, - 'productid': productid, - 'htmlname': htmlname }, - function(data) { - if (typeof data != 'undefined' && data.error == null) { - $("#" + htmlname).html(data.value).trigger('change'); - } - }, 'json'); + $.ajax({ + type: "POST", + url: '/core/ajax/vatrates.php', + data: { + 'action': action, + 'id': id; ?>, + 'productid': productid, + 'htmlname': htmlname + }, + success: function(data){ + if (typeof data != 'undefined' && data.error == null) { + $("#" + htmlname).html(data.value).trigger('change'); + } + }, + dataType: "json", + async: false + }); } // Check if decription is not empty for free line