diff --git a/InvenTree/static/script/inventree/stock.js b/InvenTree/static/script/inventree/stock.js
index 9a060636b7..ddb20ad1f1 100644
--- a/InvenTree/static/script/inventree/stock.js
+++ b/InvenTree/static/script/inventree/stock.js
@@ -79,7 +79,7 @@ function updateStock(items, options={}) {
html += "max='" + vMax + "' ";
}
- html += "type='number' id='q-" + item.pk + "'/>";
+ html += "type='number' id='q-update-" + item.pk + "'/>";
html += '';
}
@@ -128,7 +128,7 @@ function updateStock(items, options={}) {
for (idx = 0; idx < items.length; idx++) {
var item = items[idx];
- var q = $(modal).find("#q-" + item.pk).val();
+ var q = $(modal).find("#q-update-" + item.pk).val();
stocktake.push({
pk: item.pk,
@@ -229,7 +229,7 @@ function moveStockItems(items, options) {
inventreePut("/api/stock/move/",
{
location: location,
- 'parts[]': parts,
+ 'stock': parts,
'notes': notes,
},
{
@@ -246,7 +246,6 @@ function moveStockItems(items, options) {
getStockLocations({},
{
success: function(response) {
-
// Extact part row info
var parts = [];
@@ -280,7 +279,11 @@ function moveStockItems(items, options) {
`;
for (i = 0; i < items.length; i++) {
- parts.push(items[i].pk);
+
+ parts.push({
+ pk: items[i].pk,
+ quantity: items[i].quantity,
+ });
var item = items[i];
@@ -293,7 +296,7 @@ function moveStockItems(items, options) {
html += "
";
html += "
";
+ html += "type='number' id='q-move-" + item.pk + "'/>";
html += "";
}
@@ -324,6 +327,15 @@ function moveStockItems(items, options) {
return false;
}
+ // Update the quantity for each item
+ for (var ii = 0; ii < parts.length; ii++) {
+ var pk = parts[ii].pk;
+
+ var q = $(modal).find('#q-move-' + pk).val();
+
+ parts[ii].quantity = q;
+ }
+
doMove(locId, parts, notes);
});
},
diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py
index 070e7657a6..f67f97f4b6 100644
--- a/InvenTree/stock/api.py
+++ b/InvenTree/stock/api.py
@@ -151,7 +151,7 @@ class StockMove(APIView):
data = request.data
- if u'location' not in data:
+ if 'location' not in data:
raise ValidationError({'location': 'Destination must be specified'})
loc_id = data.get(u'location')
@@ -161,18 +161,34 @@ class StockMove(APIView):
except StockLocation.DoesNotExist:
raise ValidationError({'location': 'Location does not exist'})
- if u'parts[]' not in data:
- raise ValidationError({'parts[]': 'Parts list must be specified'})
+ if 'stock' not in data:
+ raise ValidationError({'stock': 'Stock list must be specified'})
+
+ stock_list = data.get('stock')
- part_list = data.get(u'parts[]')
+ if type(stock_list) is not list:
+ raise ValidationError({'stock': 'Stock must be supplied as a list'})
+
+ if 'notes' not in data:
+ raise ValidationError({'notes': 'Notes field must be supplied'})
parts = []
errors = []
- if u'notes' not in data:
- errors.append({'notes': 'Notes field must be supplied'})
+ for item in stock_list:
+ try:
+ stock_id = int(item['pk'])
+ quantity = int(item['quantity'])
+ except ValueError:
+ # Ignore this one
+ continue
+
+ print('stock:', stock_id)
+ print('quantity:', quantity)
+ """
+
for pid in part_list:
try:
part = StockItem.objects.get(pk=pid)
@@ -189,6 +205,10 @@ class StockMove(APIView):
if part.move(location, data.get('notes'), request.user):
n += 1
+ """
+
+ n = 0
+
return Response({'success': 'Moved {n} parts to {loc}'.format(
n=n,
loc=str(location)