mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-02 11:40:58 +00:00
Implemented API to move multiple items at once
- Added ability to override request method in inventreeUpdate - Added inventree/script/stock.js to handle stock API js - Added StockMove API endpoint
This commit is contained in:
@ -46,6 +46,12 @@ function inventreeUpdate(url, data={}, options={}) {
|
||||
data["_is_final"] = true;
|
||||
}
|
||||
|
||||
var method = 'put';
|
||||
|
||||
if ('method' in options) {
|
||||
method = options.method;
|
||||
}
|
||||
|
||||
// Middleware token required for data update
|
||||
//var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
|
||||
var csrftoken = getCookie('csrftoken');
|
||||
@ -55,7 +61,7 @@ function inventreeUpdate(url, data={}, options={}) {
|
||||
xhr.setRequestHeader('X-CSRFToken', csrftoken);
|
||||
},
|
||||
url: url,
|
||||
type: 'put',
|
||||
type: method,
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
success: function(response, status) {
|
||||
|
72
InvenTree/static/script/inventree/stock.js
Normal file
72
InvenTree/static/script/inventree/stock.js
Normal file
@ -0,0 +1,72 @@
|
||||
|
||||
function moveStock(rows, options) {
|
||||
|
||||
var modal = '#modal-form';
|
||||
|
||||
if ('modal' in options) {
|
||||
modal = options.modal;
|
||||
}
|
||||
|
||||
if (rows.length == 0) {
|
||||
alert('No stock items selected');
|
||||
return;
|
||||
}
|
||||
|
||||
function doMove(location, parts) {
|
||||
inventreeUpdate("/api/stock/move/",
|
||||
{
|
||||
location: location,
|
||||
parts: parts
|
||||
},
|
||||
{
|
||||
success: function(response) {
|
||||
closeModal(modal);
|
||||
if (options.success) {
|
||||
options.success();
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
alert('error!:\n' + error);
|
||||
},
|
||||
method: 'post'
|
||||
});
|
||||
}
|
||||
|
||||
getStockLocations({},
|
||||
{
|
||||
success: function(response) {
|
||||
openModal(modal);
|
||||
modalSetTitle(modal, "Move " + rows.length + " stock items");
|
||||
modalSetButtonText(modal, "Move");
|
||||
|
||||
// Extact part row info
|
||||
var parts = [];
|
||||
|
||||
for (i = 0; i < rows.length; i++) {
|
||||
parts.push(rows[i].pk);
|
||||
}
|
||||
|
||||
var form = "<select class='select' id='stock-location'>";
|
||||
|
||||
for (i = 0; i < response.length; i++) {
|
||||
var loc = response[i];
|
||||
|
||||
form += makeOption(loc.pk, loc.name + ' - <i>' + loc.description + '</i>');
|
||||
}
|
||||
|
||||
form += "</select">
|
||||
|
||||
modalSetContent(modal, form);
|
||||
attachSelect(modal);
|
||||
|
||||
$(modal).on('click', '#modal-form-submit', function() {
|
||||
var locId = $(modal).find("#stock-location").val();
|
||||
|
||||
doMove(locId, parts);
|
||||
});
|
||||
},
|
||||
error: function(error) {
|
||||
alert('Error getting stock locations:\n' + error.error);
|
||||
}
|
||||
});
|
||||
}
|
@ -61,6 +61,9 @@ function modalSetButtonText(modal, text) {
|
||||
$(modal).find("#modal-form-submit").html(text);
|
||||
}
|
||||
|
||||
function closeModal(modal='#modal-form') {
|
||||
$(modal).modal('hide');
|
||||
}
|
||||
|
||||
function openModal(modal, title='', content='') {
|
||||
|
||||
|
Reference in New Issue
Block a user