mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-19 21:45:39 +00:00
Start of API forms for stock item
This commit is contained in:
@ -179,6 +179,7 @@ function constructChangeForm(fields, options) {
|
||||
// Request existing data from the API endpoint
|
||||
$.ajax({
|
||||
url: options.url,
|
||||
data: options.params || {},
|
||||
type: 'GET',
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
@ -194,6 +195,17 @@ function constructChangeForm(fields, options) {
|
||||
fields[field].value = data[field];
|
||||
}
|
||||
}
|
||||
|
||||
// An optional function can be provided to process the returned results,
|
||||
// before they are rendered to the form
|
||||
if (options.processResults) {
|
||||
var processed = options.processResults(data, fields, options);
|
||||
|
||||
// If the processResults function returns data, it will be stored
|
||||
if (processed) {
|
||||
data = processed;
|
||||
}
|
||||
}
|
||||
|
||||
// Store the entire data object
|
||||
options.instance = data;
|
||||
|
@ -68,6 +68,95 @@ function locationFields() {
|
||||
}
|
||||
|
||||
|
||||
function stockItemFields(options={}) {
|
||||
var fields = {
|
||||
part: {},
|
||||
supplier_part: {
|
||||
filters: {
|
||||
part_detail: true,
|
||||
supplier_detail: true,
|
||||
},
|
||||
adjustFilters: function(query, opts) {
|
||||
var part = getFormFieldValue('part', {}, opts);
|
||||
|
||||
if (part) {
|
||||
query.part = part;
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
},
|
||||
serial: {},
|
||||
status: {},
|
||||
expiry_date: {},
|
||||
batch: {},
|
||||
purchase_price: {},
|
||||
purchase_price_currency: {},
|
||||
packaging: {},
|
||||
link: {},
|
||||
delete_on_deplete: {},
|
||||
// owner: {},
|
||||
};
|
||||
|
||||
// Remove stock expiry fields if feature is not enabled
|
||||
if (!global_settings.STOCK_ENABLE_EXPIRY) {
|
||||
delete fields['expiry_date'];
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
function stockItemGroups(options={}) {
|
||||
return {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Launch a modal form to edit a given StockItem
|
||||
*/
|
||||
function editStockItem(pk, options={}) {
|
||||
|
||||
var url = `/api/stock/${pk}/`;
|
||||
|
||||
var fields = stockItemFields(options);
|
||||
|
||||
// Prevent editing of the "part"
|
||||
fields.part.hidden = true;
|
||||
|
||||
var groups = stockItemGroups(options);
|
||||
|
||||
constructForm(url, {
|
||||
fields: fields,
|
||||
groups: groups,
|
||||
title: '{% trans "Edit Stock Item" %}',
|
||||
params: {
|
||||
part_detail: true,
|
||||
supplier_part_detail: true,
|
||||
},
|
||||
processResults: function(data, fields, options) {
|
||||
// Callback when StockItem data is received from server
|
||||
|
||||
if (data.part_detail.trackable) {
|
||||
delete options.fields.delete_on_deplete;
|
||||
} else {
|
||||
// Remove serial number field if part is not trackable
|
||||
delete options.fields.serial;
|
||||
}
|
||||
|
||||
// Remove pricing fields if part is not purchaseable
|
||||
if (!data.part_detail.purchaseable) {
|
||||
delete options.fields.supplier_part;
|
||||
delete options.fields.purchase_price;
|
||||
delete options.fields.purchase_price_currency;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/* Stock API functions
|
||||
* Requires api.js to be loaded first
|
||||
*/
|
||||
|
Reference in New Issue
Block a user