From 990808ec03b1dd4f8be9b6095501aa2fcc225aab Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 25 Apr 2019 23:16:54 +1000 Subject: [PATCH] Fix code to move multiple parts via AJAX / JSON --- InvenTree/static/script/inventree/stock.js | 50 +++++++++++----------- InvenTree/stock/api.py | 9 ++-- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/InvenTree/static/script/inventree/stock.js b/InvenTree/static/script/inventree/stock.js index a32e446ad6..e117ef0240 100644 --- a/InvenTree/static/script/inventree/stock.js +++ b/InvenTree/static/script/inventree/stock.js @@ -149,9 +149,7 @@ function updateStock(items, options={}) { method: 'post', }).then(function(response) { closeModal(modal); - if (options.success) { - options.success(); - } + afterForm(response, options); }).fail(function(xhr, status, error) { alert(error); }); @@ -227,33 +225,26 @@ function moveStockItems(items, options) { function doMove(location, parts, notes) { inventreeUpdate("/api/stock/move/", - { - location: location, - 'parts[]': parts, - 'notes': notes, - }, - { - success: function(response) { - closeModal(modal); - if (options.success) { - options.success(); - } - }, - error: function(error) { - alert('error!:\n' + error); - }, - method: 'post' - }); + { + location: location, + 'parts[]': parts, + 'notes': notes, + }, + { + method: 'post', + }).then(function(response) { + closeModal(modal); + afterForm(response, options); + }).fail(function(xhr, status, error) { + alert(error); + }); } + getStockLocations({}, { success: function(response) { - openModal({ - modal: modal, - title: "Move " + items.length + " stock items", - submit_text: "Move" - }); + // Extact part row info var parts = []; @@ -290,7 +281,14 @@ function moveStockItems(items, options) { html += "\n"; - modalSetContent(modal, html); + openModal({ + modal: modal, + title: "Move " + items.length + " stock items", + submit_text: "Move", + content: html + }); + + //modalSetContent(modal, html); attachSelect(modal); $(modal).find('#note-warning').hide(); diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 2aae16e58b..2ac2ea584e 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -166,12 +166,15 @@ class StockMove(APIView): if len(errors) > 0: raise ValidationError(errors) + n = 0 + for part in parts: - part.move(location, data.get('notes'), request.user) + if part.move(location, data.get('notes'), request.user): + n += 1 return Response({'success': 'Moved {n} parts to {loc}'.format( - n=len(parts), - loc=location.name + n=n, + loc=str(location) )})