2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-30 04:26:44 +00:00

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 += "max='" + vMax + "' ";
} }
html += "type='number' id='q-" + item.pk + "'/></td>"; html += "type='number' id='q-update-" + item.pk + "'/></td>";
html += '</tr>'; html += '</tr>';
} }
@ -128,7 +128,7 @@ function updateStock(items, options={}) {
for (idx = 0; idx < items.length; idx++) { for (idx = 0; idx < items.length; idx++) {
var item = items[idx]; var item = items[idx];
var q = $(modal).find("#q-" + item.pk).val(); var q = $(modal).find("#q-update-" + item.pk).val();
stocktake.push({ stocktake.push({
pk: item.pk, pk: item.pk,
@ -229,7 +229,7 @@ function moveStockItems(items, options) {
inventreePut("/api/stock/move/", inventreePut("/api/stock/move/",
{ {
location: location, location: location,
'parts[]': parts, 'stock': parts,
'notes': notes, 'notes': notes,
}, },
{ {
@ -246,7 +246,6 @@ function moveStockItems(items, options) {
getStockLocations({}, getStockLocations({},
{ {
success: function(response) { success: function(response) {
// Extact part row info // Extact part row info
var parts = []; var parts = [];
@ -280,7 +279,11 @@ function moveStockItems(items, options) {
`; `;
for (i = 0; i < items.length; i++) { 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]; var item = items[i];
@ -293,7 +296,7 @@ function moveStockItems(items, options) {
html += "<td>"; html += "<td>";
html += "<input class='form-control' min='0' max='" + item.quantity + "'"; html += "<input class='form-control' min='0' max='" + item.quantity + "'";
html += " value='" + 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>"; html += "</tr>";
} }
@ -324,6 +327,15 @@ function moveStockItems(items, options) {
return false; 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); doMove(locId, parts, notes);
}); });
}, },

View File

@ -151,7 +151,7 @@ class StockMove(APIView):
data = request.data data = request.data
if u'location' not in data: if 'location' not in data:
raise ValidationError({'location': 'Destination must be specified'}) raise ValidationError({'location': 'Destination must be specified'})
loc_id = data.get(u'location') loc_id = data.get(u'location')
@ -161,18 +161,34 @@ class StockMove(APIView):
except StockLocation.DoesNotExist: except StockLocation.DoesNotExist:
raise ValidationError({'location': 'Location does not exist'}) raise ValidationError({'location': 'Location does not exist'})
if u'parts[]' not in data: if 'stock' not in data:
raise ValidationError({'parts[]': 'Parts list must be specified'}) 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 = [] parts = []
errors = [] errors = []
if u'notes' not in data: for item in stock_list:
errors.append({'notes': 'Notes field must be supplied'}) 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: for pid in part_list:
try: try:
part = StockItem.objects.get(pk=pid) part = StockItem.objects.get(pk=pid)
@ -189,6 +205,10 @@ class StockMove(APIView):
if part.move(location, data.get('notes'), request.user): if part.move(location, data.get('notes'), request.user):
n += 1 n += 1
"""
n = 0
return Response({'success': 'Moved {n} parts to {loc}'.format( return Response({'success': 'Moved {n} parts to {loc}'.format(
n=n, n=n,
loc=str(location) loc=str(location)