mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Fixes for JSON API
- Set content type - Stringify JSON data - Finish API to stocktake multiple parts
This commit is contained in:
parent
1363fa9f1f
commit
b6944620dd
@ -23,6 +23,7 @@ function inventreeGet(url, filters={}, options={}) {
|
|||||||
type: 'GET',
|
type: 'GET',
|
||||||
data: filters,
|
data: filters,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
|
contentType: 'application/json',
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
console.log('Success GET data at ' + url);
|
console.log('Success GET data at ' + url);
|
||||||
if (options.success) {
|
if (options.success) {
|
||||||
@ -62,8 +63,9 @@ function inventreeUpdate(url, data={}, options={}) {
|
|||||||
},
|
},
|
||||||
url: url,
|
url: url,
|
||||||
type: method,
|
type: method,
|
||||||
data: data,
|
data: JSON.stringify(data),
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
|
contentType: 'application/json',
|
||||||
success: function(response, status) {
|
success: function(response, status) {
|
||||||
response['_status_code'] = status;
|
response['_status_code'] = status;
|
||||||
console.log('UPDATE object to ' + url + ' - result = ' + status);
|
console.log('UPDATE object to ' + url + ' - result = ' + status);
|
||||||
|
@ -16,7 +16,7 @@ function moveStockItems(items, options) {
|
|||||||
inventreeUpdate("/api/stock/move/",
|
inventreeUpdate("/api/stock/move/",
|
||||||
{
|
{
|
||||||
location: location,
|
location: location,
|
||||||
parts: parts
|
'parts[]': parts
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
@ -97,8 +97,67 @@ function countStockItems(items, options) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tbl = "<table class='table table-striped table-condensed' id='stocktake-table'></table>";
|
||||||
|
|
||||||
openModal(modal);
|
openModal(modal);
|
||||||
modalSetTitle(modal, 'Stocktake');
|
modalSetTitle(modal, 'Stocktake ' + items.length + ' items');
|
||||||
|
|
||||||
|
$(modal).find('.modal-form-content').html(tbl);
|
||||||
|
|
||||||
|
$(modal).find('#stocktake-table').bootstrapTable({
|
||||||
|
data: items,
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
checkbox: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'part.name',
|
||||||
|
title: 'Part',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'location.name',
|
||||||
|
title: 'Location',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'quantity',
|
||||||
|
title: 'Quantity',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
$(modal).on('click', '#modal-form-submit', function() {
|
||||||
|
var selections = $(modal).find('#stocktake-table').bootstrapTable('getSelections');
|
||||||
|
|
||||||
|
var stocktake = [];
|
||||||
|
|
||||||
|
console.log('Performing stocktake on ' + selections.length + ' items');
|
||||||
|
|
||||||
|
for (i = 0; i<selections.length; i++) {
|
||||||
|
var item = {
|
||||||
|
pk: selections[i].pk,
|
||||||
|
quantity: selections[i].quantity,
|
||||||
|
};
|
||||||
|
|
||||||
|
stocktake.push(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
inventreeUpdate("/api/stock/stocktake/",
|
||||||
|
{
|
||||||
|
'items[]': stocktake,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
success: function(response) {
|
||||||
|
closeModal(modal);
|
||||||
|
if (options.success) {
|
||||||
|
options.success();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
alert(error);
|
||||||
|
},
|
||||||
|
method: 'post',
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteStockItems(items, options) {
|
function deleteStockItems(items, options) {
|
||||||
|
@ -59,12 +59,13 @@ class StockStocktake(APIView):
|
|||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
|
|
||||||
data = request.data
|
if not 'items[]' in request.data:
|
||||||
|
raise ValidationError({'items[]:' 'Request must contain list of items'})
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
|
|
||||||
# Ensure each entry is valid
|
# Ensure each entry is valid
|
||||||
for entry in data:
|
for entry in request.data['items[]']:
|
||||||
if not 'pk' in entry:
|
if not 'pk' in entry:
|
||||||
raise ValidationError({'pk': 'Each entry must contain pk field'})
|
raise ValidationError({'pk': 'Each entry must contain pk field'})
|
||||||
if not 'quantity' in entry:
|
if not 'quantity' in entry:
|
||||||
@ -80,6 +81,9 @@ class StockStocktake(APIView):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValidationError({'quantity': 'Quantity must be an integer'})
|
raise ValidationError({'quantity': 'Quantity must be an integer'})
|
||||||
|
|
||||||
|
if item['quantity'] < 0:
|
||||||
|
raise ValidationError({'quantity': 'Quantity must be >= 0'})
|
||||||
|
|
||||||
items.append(item)
|
items.append(item)
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
@ -111,7 +115,7 @@ class StockMove(APIView):
|
|||||||
if not u'parts[]' in data:
|
if not u'parts[]' in data:
|
||||||
raise ValidationError({'parts[]': 'Parts list must be specified'})
|
raise ValidationError({'parts[]': 'Parts list must be specified'})
|
||||||
|
|
||||||
part_list = data.getlist(u'parts[]')
|
part_list = data.get(u'parts[]')
|
||||||
|
|
||||||
parts = []
|
parts = []
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user