Pass stock move quantity through per item

This commit is contained in:
Oliver Walters 2019-05-11 00:04:45 +10:00
parent 99c0921113
commit 8d5c4c521c
2 changed files with 44 additions and 12 deletions

View File

@ -79,7 +79,7 @@ function updateStock(items, options={}) {
html += "max='" + vMax + "' ";
}
html += "type='number' id='q-" + item.pk + "'/></td>";
html += "type='number' id='q-update-" + item.pk + "'/></td>";
html += '</tr>';
}
@ -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 += "<td>";
html += "<input class='form-control' min='0' max='" + item.quantity + "'";
html += " value='" + item.quantity + "'";
html += "type='number' id='q-" + item.pk + "'/></td>";
html += "type='number' id='q-move-" + item.pk + "'/></td>";
html += "</tr>";
}
@ -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);
});
},

View File

@ -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)