diff --git a/InvenTree/static/script/inventree/api.js b/InvenTree/static/script/inventree/api.js index b45951ed03..fab1450a00 100644 --- a/InvenTree/static/script/inventree/api.js +++ b/InvenTree/static/script/inventree/api.js @@ -18,7 +18,7 @@ function getCookie(name) { } function inventreeGet(url, filters={}, options={}) { - $.ajax({ + return $.ajax({ url: url, type: 'GET', data: filters, @@ -39,7 +39,7 @@ function inventreeGet(url, filters={}, options={}) { }); } } - }) + }); } function inventreeUpdate(url, data={}, options={}) { @@ -57,7 +57,7 @@ function inventreeUpdate(url, data={}, options={}) { //var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val(); var csrftoken = getCookie('csrftoken'); - $.ajax({ + return $.ajax({ beforeSend: function(xhr, settings) { xhr.setRequestHeader('X-CSRFToken', csrftoken); }, @@ -69,20 +69,12 @@ function inventreeUpdate(url, data={}, options={}) { success: function(response, status) { response['_status_code'] = status; console.log('UPDATE object to ' + url + ' - result = ' + status); - if (options.success) { - options.success(response); - } }, error: function(xhr, ajaxOptions, thrownError) { console.error('Error on UPDATE to ' + url); console.error(thrownError); - if (options.error) { - options.error({ - error: thrownError - }); } - } - }) + }); } // Return list of parts with optional filters diff --git a/InvenTree/static/script/inventree/stock.js b/InvenTree/static/script/inventree/stock.js index 8fd187c3b5..5786ac2622 100644 --- a/InvenTree/static/script/inventree/stock.js +++ b/InvenTree/static/script/inventree/stock.js @@ -50,11 +50,12 @@ function updateStock(items, options={}) { var item = items[idx]; var vMin = 0; - var vMax = item.quantity; + var vMax = 0; var vCur = item.quantity; if (options.action == 'remove') { vCur = 0; + vMax = item.quantity; } else if (options.action == 'add') { vCur = 0; @@ -140,18 +141,15 @@ function updateStock(items, options={}) { 'notes': $(modal).find('#stocktake-notes').val() }, { - success: function(response) { - closeModal(modal); - if (options.success) { - options.success(); - } - }, - error: function(error) { - alert(error); - }, - method: 'post' - } - ); + method: 'post', + }).then(function(response) { + closeModal(modal); + if (options.success) { + options.success(); + } + }).fail(function(xhr, status, error) { + alert(error); + }); }); } @@ -162,20 +160,14 @@ function adjustStock(options) { else { // Lookup of individual item if (options.query.pk) { - getStockDetail(options.query.pk, - { - success: function(response) { - updateStock([response], options); - } - }); + getStockDetail(options.query.pk).then(function(response) { + updateStock([response], options); + }); } else { - getStockList(options.query, - { - success: function(response) { - updateStock(response, options); - } - }); + getStockList(options.query).then(function(response) { + updateStock(response, options); + }); } } }