2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 19:20:55 +00:00

Merge remote-tracking branch 'inventree/master' into partial-shipment

# Conflicts:
#	InvenTree/InvenTree/version.py
#	InvenTree/order/models.py
This commit is contained in:
Oliver
2021-11-11 12:35:59 +11:00
120 changed files with 3551 additions and 1760 deletions

View File

@ -2,8 +2,6 @@
{% load inventree_extras %}
/* globals
renderErrorMessage,
showAlertDialog,
*/
/* exported
@ -63,11 +61,17 @@ function inventreeGet(url, filters={}, options={}) {
},
error: function(xhr, ajaxOptions, thrownError) {
console.error('Error on GET at ' + url);
console.error(thrownError);
if (thrownError) {
console.error('Error: ' + thrownError);
}
if (options.error) {
options.error({
error: thrownError
});
} else {
showApiError(xhr, url);
}
}
});
@ -104,6 +108,8 @@ function inventreeFormDataUpload(url, data, options={}) {
if (options.error) {
options.error(xhr, status, error);
} else {
showApiError(xhr, url);
}
}
});
@ -139,6 +145,8 @@ function inventreePut(url, data={}, options={}) {
} else {
console.error(`Error on ${method} to '${url}' - STATUS ${xhr.status}`);
console.error(thrownError);
showApiError(xhr, url);
}
},
complete: function(xhr, status) {
@ -162,13 +170,15 @@ function inventreeDelete(url, options={}) {
return inventreePut(url, {}, options);
}
function showApiError(xhr) {
/*
* Display a notification with error information
*/
function showApiError(xhr, url) {
var title = null;
var message = null;
switch (xhr.status) {
switch (xhr.status || 0) {
// No response
case 0:
title = '{% trans "No Response" %}';
@ -208,7 +218,11 @@ function showApiError(xhr) {
}
message += '<hr>';
message += renderErrorMessage(xhr);
message += `URL: ${url}`;
showAlertDialog(title, message);
showMessage(title, {
style: 'danger',
icon: 'fas fa-server icon-red',
details: message,
});
}

View File

@ -10,7 +10,6 @@
modalSetSubmitText,
modalShowSubmitButton,
modalSubmit,
showAlertOrCache,
showQuestionDialog,
*/
@ -36,7 +35,7 @@ function makeBarcodeInput(placeholderText='', hintText='') {
<label class='control-label' for='barcode'>{% trans "Barcode" %}</label>
<div class='controls'>
<div class='input-group'>
<span class='input-group-addon'>
<span class='input-group-text'>
<span class='fas fa-qrcode'></span>
</span>
<input id='barcode' class='textinput textInput form-control' type='text' name='barcode' placeholder='${placeholderText}'>
@ -59,7 +58,7 @@ function makeNotesField(options={}) {
<label class='control-label' for='notes'>{% trans "Notes" %}</label>
<div class='controls'>
<div class='input-group'>
<span class='input-group-addon'>
<span class='input-group-text'>
<span class='fas fa-sticky-note'></span>
</span>
<input id='notes' class='textinput textInput form-control' type='text' name='notes' placeholder='${placeholder}'>
@ -258,7 +257,7 @@ function barcodeDialog(title, options={}) {
$(modal).modal({
backdrop: 'static',
keyboard: false,
keyboard: user_settings.FORMS_CLOSE_USING_ESCAPE,
});
if (options.preShow) {
@ -480,10 +479,13 @@ function barcodeCheckIn(location_id) {
$(modal).modal('hide');
if (status == 'success' && 'success' in response) {
showAlertOrCache('alert-success', response.success, true);
addCachedAlert(response.success);
location.reload();
} else {
showAlertOrCache('alert-success', '{% trans "Error transferring stock" %}', false);
showMessage('{% trans "Error transferring stock" %}', {
style: 'danger',
icon: 'fas fa-times-circle',
});
}
}
}
@ -604,10 +606,12 @@ function scanItemsIntoLocation(item_id_list, options={}) {
$(modal).modal('hide');
if (status == 'success' && 'success' in response) {
showAlertOrCache('alert-success', response.success, true);
addCachedAlert(response.success);
location.reload();
} else {
showAlertOrCache('alert-danger', '{% trans "Error transferring stock" %}', false);
showMessage('{% trans "Error transferring stock" %}', {
style: 'danger',
});
}
}
}

View File

@ -43,11 +43,18 @@ function buildFormFields() {
}
},
sales_order: {
icon: 'fa-truck',
},
batch: {},
target_date: {},
take_from: {},
destination: {},
target_date: {
icon: 'fa-calendar-alt',
},
take_from: {
icon: 'fa-sitemap',
},
destination: {
icon: 'fa-sitemap',
},
link: {
icon: 'fa-link',
},
@ -339,7 +346,7 @@ function completeBuildOutputs(build_id, outputs, options={}) {
break;
default:
$(opts.modal).modal('hide');
showApiError(xhr);
showApiError(xhr, opts.url);
break;
}
}
@ -1527,7 +1534,7 @@ function allocateStockToBuild(build_id, part_id, bom_items, options={}) {
break;
default:
$(opts.modal).modal('hide');
showApiError(xhr);
showApiError(xhr, opts.url);
break;
}
}

View File

@ -281,7 +281,7 @@ function setupFilterList(tableKey, table, target) {
// One blank slate, please
element.empty();
element.append(`<button id='reload-${tableKey}' title='{% trans "Reload data" %}' class='btn btn-outline-secondary filter-tag'><span class='fas fa-redo-alt'></span></button>`);
element.append(`<button id='reload-${tableKey}' title='{% trans "Reload data" %}' class='btn btn-outline-secondary filter-button'><span class='fas fa-redo-alt'></span></button>`);
// Callback for reloading the table
element.find(`#reload-${tableKey}`).click(function() {
@ -293,11 +293,10 @@ function setupFilterList(tableKey, table, target) {
return;
}
// If there are filters currently "in use", add them in!
element.append(`<button id='${add}' title='{% trans "Add new filter" %}' class='btn btn-outline-secondary filter-tag'><span class='fas fa-filter'></span></button>`);
element.append(`<button id='${add}' title='{% trans "Add new filter" %}' class='btn btn-outline-secondary filter-button'><span class='fas fa-filter'></span></button>`);
if (Object.keys(filters).length > 0) {
element.append(`<button id='${clear}' title='{% trans "Clear all filters" %}' class='btn btn-outline-secondary filter-tag'><span class='fas fa-backspace icon-red'></span></button>`);
element.append(`<button id='${clear}' title='{% trans "Clear all filters" %}' class='btn btn-outline-secondary filter-button'><span class='fas fa-backspace icon-red'></span></button>`);
}
for (var key in filters) {
@ -320,7 +319,7 @@ function setupFilterList(tableKey, table, target) {
html += generateAvailableFilterList(tableKey);
html += generateFilterInput(tableKey);
html += `<button title='{% trans "Create filter" %}' class='btn btn-outline-secondary filter-tag' id='${make}'><span class='fas fa-plus'></span></button>`;
html += `<button title='{% trans "Create filter" %}' class='btn btn-outline-secondary filter-button' id='${make}'><span class='fas fa-plus'></span></button>`;
element.append(html);

View File

@ -19,13 +19,17 @@
renderStockLocation,
renderSupplierPart,
renderUser,
showAlertDialog,
showAlertOrCache,
showApiError,
*/
/* exported
setFormGroupVisibility
clearFormInput,
disableFormInput,
enableFormInput,
hideFormInput,
setFormGroupVisibility,
showFormInput,
*/
/**
@ -113,6 +117,10 @@ function canDelete(OPTIONS) {
*/
function getApiEndpointOptions(url, callback) {
if (!url) {
return;
}
// Return the ajax request object
$.ajax({
url: url,
@ -123,9 +131,10 @@ function getApiEndpointOptions(url, callback) {
json: 'application/json',
},
success: callback,
error: function() {
error: function(xhr) {
// TODO: Handle error
console.log(`ERROR in getApiEndpointOptions at '${url}'`);
showApiError(xhr, url);
}
});
}
@ -181,6 +190,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',
@ -188,6 +198,17 @@ function constructChangeForm(fields, options) {
json: 'application/json',
},
success: function(data) {
// 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;
}
}
// Push existing 'value' to each field
for (const field in data) {
@ -199,12 +220,14 @@ function constructChangeForm(fields, options) {
// Store the entire data object
options.instance = data;
constructFormBody(fields, options);
},
error: function() {
error: function(xhr) {
// TODO: Handle error here
console.log(`ERROR in constructChangeForm at '${options.url}'`);
showApiError(xhr, options.url);
}
});
}
@ -241,9 +264,11 @@ function constructDeleteForm(fields, options) {
constructFormBody(fields, options);
},
error: function() {
error: function(xhr) {
// TODO: Handle error here
console.log(`ERROR in constructDeleteForm at '${options.url}`);
showApiError(xhr, options.url);
}
});
}
@ -321,10 +346,12 @@ function constructForm(url, options) {
constructCreateForm(OPTIONS.actions.POST, options);
} else {
// User does not have permission to POST to the endpoint
showAlertDialog(
'{% trans "Action Prohibited" %}',
'{% trans "Create operation not allowed" %}'
);
showMessage('{% trans "Action Prohibited" %}', {
style: 'danger',
details: '{% trans "Create operation not allowed" %}',
icon: 'fas fa-user-times',
});
console.log(`'POST action unavailable at ${url}`);
}
break;
@ -334,10 +361,12 @@ function constructForm(url, options) {
constructChangeForm(OPTIONS.actions.PUT, options);
} else {
// User does not have permission to PUT/PATCH to the endpoint
showAlertDialog(
'{% trans "Action Prohibited" %}',
'{% trans "Update operation not allowed" %}'
);
showMessage('{% trans "Action Prohibited" %}', {
style: 'danger',
details: '{% trans "Update operation not allowed" %}',
icon: 'fas fa-user-times',
});
console.log(`${options.method} action unavailable at ${url}`);
}
break;
@ -346,10 +375,12 @@ function constructForm(url, options) {
constructDeleteForm(OPTIONS.actions.DELETE, options);
} else {
// User does not have permission to DELETE to the endpoint
showAlertDialog(
'{% trans "Action Prohibited" %}',
'{% trans "Delete operation not allowed" %}'
);
showMessage('{% trans "Action Prohibited" %}', {
style: 'danger',
details: '{% trans "Delete operation not allowed" %}',
icon: 'fas fa-user-times',
});
console.log(`DELETE action unavailable at ${url}`);
}
break;
@ -358,10 +389,12 @@ function constructForm(url, options) {
// TODO?
} else {
// User does not have permission to GET to the endpoint
showAlertDialog(
'{% trans "Action Prohibited" %}',
'{% trans "View operation not allowed" %}'
);
showMessage('{% trans "Action Prohibited" %}', {
style: 'danger',
details: '{% trans "View operation not allowed" %}',
icon: 'fas fa-user-times',
});
console.log(`GET action unavailable at ${url}`);
}
break;
@ -691,6 +724,11 @@ function submitFormData(fields, options) {
data = form_data;
}
// Optionally pre-process the data before uploading to the server
if (options.processBeforeUpload) {
data = options.processBeforeUpload(data);
}
// Submit data
upload_func(
options.url,
@ -708,7 +746,9 @@ function submitFormData(fields, options) {
break;
default:
$(options.modal).modal('hide');
showApiError(xhr);
console.log(`upload error at ${options.url}`);
showApiError(xhr, options.url);
break;
}
}
@ -885,19 +925,19 @@ function handleFormSuccess(response, options) {
// Display any messages
if (response && response.success) {
showAlertOrCache('alert-success', response.success, cache);
showAlertOrCache(response.success, cache, {style: 'success'});
}
if (response && response.info) {
showAlertOrCache('alert-info', response.info, cache);
showAlertOrCache(response.info, cache, {style: 'info'});
}
if (response && response.warning) {
showAlertOrCache('alert-warning', response.warning, cache);
showAlertOrCache(response.warning, cache, {style: 'warning'});
}
if (response && response.danger) {
showAlertOrCache('alert-danger', response.danger, cache);
showAlertOrCache(response.danger, cache, {style: 'danger'});
}
if (options.onSuccess) {
@ -1236,6 +1276,35 @@ function initializeGroups(fields, options) {
}
}
// Clear a form input
function clearFormInput(name, options) {
updateFieldValue(name, null, {}, options);
}
// Disable a form input
function disableFormInput(name, options) {
$(options.modal).find(`#id_${name}`).prop('disabled', true);
}
// Enable a form input
function enableFormInput(name, options) {
$(options.modal).find(`#id_${name}`).prop('disabled', false);
}
// Hide a form input
function hideFormInput(name, options) {
$(options.modal).find(`#div_id_${name}`).hide();
}
// Show a form input
function showFormInput(name, options) {
$(options.modal).find(`#div_id_${name}`).show();
}
// Hide a form group
function hideFormGroup(group, options) {
$(options.modal).find(`#form-panel-${group}`).hide();

View File

@ -399,19 +399,19 @@ function afterForm(response, options) {
// Display any messages
if (response.success) {
showAlertOrCache('alert-success', response.success, cache);
showAlertOrCache(response.success, cache, {style: 'success'});
}
if (response.info) {
showAlertOrCache('alert-info', response.info, cache);
showAlertOrCache(response.info, cache, {style: 'info'});
}
if (response.warning) {
showAlertOrCache('alert-warning', response.warning, cache);
showAlertOrCache(response.warning, cache, {style: 'warning'});
}
if (response.danger) {
showAlertOrCache('alert-danger', response.danger, cache);
showAlertOrCache(response.danger, cache, {style: 'danger'});
}
// Was a callback provided?

View File

@ -589,7 +589,7 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) {
break;
default:
$(opts.modal).modal('hide');
showApiError(xhr);
showApiError(xhr, opts.url);
break;
}
}

View File

@ -373,24 +373,23 @@ function duplicatePart(pk, options={}) {
}
/* Toggle the 'starred' status of a part.
* Performs AJAX queries and updates the display on the button.
*
* options:
* - button: ID of the button (default = '#part-star-icon')
* - URL: API url of the object
* - user: pk of the user
*/
function toggleStar(options) {
/* Toggle the 'starred' status of a part.
* Performs AJAX queries and updates the display on the button.
*
* options:
* - button: ID of the button (default = '#part-star-icon')
* - part: pk of the part object
* - user: pk of the user
*/
var url = `/api/part/${options.part}/`;
inventreeGet(url, {}, {
inventreeGet(options.url, {}, {
success: function(response) {
var starred = response.starred;
inventreePut(
url,
options.url,
{
starred: !starred,
},
@ -398,9 +397,19 @@ function toggleStar(options) {
method: 'PATCH',
success: function(response) {
if (response.starred) {
$(options.button).addClass('icon-yellow');
$(options.button).removeClass('fa fa-bell-slash').addClass('fas fa-bell icon-green');
$(options.button).attr('title', '{% trans "You are subscribed to notifications for this item" %}');
showMessage('{% trans "You have subscribed to notifications for this item" %}', {
style: 'success',
});
} else {
$(options.button).removeClass('icon-yellow');
$(options.button).removeClass('fas fa-bell icon-green').addClass('fa fa-bell-slash');
$(options.button).attr('title', '{% trans "Subscribe to notifications for this item" %}');
showMessage('{% trans "You have unsubscribed to notifications for this item" %}', {
style: 'warning',
});
}
}
}
@ -410,12 +419,12 @@ function toggleStar(options) {
}
function partStockLabel(part) {
function partStockLabel(part, options={}) {
if (part.in_stock) {
return `<span class='badge rounded-pill bg-success'>{% trans "Stock" %}: ${part.in_stock}</span>`;
return `<span class='badge rounded-pill bg-success ${options.classes}'>{% trans "Stock" %}: ${part.in_stock}</span>`;
} else {
return `<span class='badge rounded-pill bg-danger'>{% trans "No Stock" %}</span>`;
return `<span class='badge rounded-pill bg-danger ${options.classes}'>{% trans "No Stock" %}</span>`;
}
}
@ -443,7 +452,7 @@ function makePartIcons(part) {
}
if (part.starred) {
html += makeIconBadge('fa-star', '{% trans "Starred part" %}');
html += makeIconBadge('fa-bell icon-green', '{% trans "Subscribed part" %}');
}
if (part.salable) {
@ -451,7 +460,7 @@ function makePartIcons(part) {
}
if (!part.active) {
html += `<span class='badge badge-right rounded-pill bg-warning'>{% trans "Inactive" %}</span>`;
html += `<span class='badge badge-right rounded-pill bg-warning'>{% trans "Inactive" %}</span> `;
}
return html;
@ -983,7 +992,7 @@ function loadPartTable(table, url, options={}) {
}
});
var grid_view = inventreeLoad('part-grid-view') == 1;
var grid_view = options.gridView && inventreeLoad('part-grid-view') == 1;
$(table).inventreeTable({
url: url,
@ -1011,7 +1020,7 @@ function loadPartTable(table, url, options={}) {
$('#view-part-list').removeClass('btn-outline-secondary').addClass('btn-secondary');
}
},
buttons: [
buttons: options.gridView ? [
{
icon: 'fas fa-bars',
attributes: {
@ -1044,7 +1053,7 @@ function loadPartTable(table, url, options={}) {
);
}
}
],
] : [],
customView: function(data) {
var html = '';
@ -1133,8 +1142,10 @@ function loadPartTable(table, url, options={}) {
}
/*
* Display a table of part categories
*/
function loadPartCategoryTable(table, options) {
/* Display a table of part categories */
var params = options.params || {};
@ -1148,6 +1159,13 @@ function loadPartCategoryTable(table, options) {
filters = loadTableFilters(filterKey);
}
var tree_view = options.allowTreeView && inventreeLoad('category-tree-view') == 1;
if (tree_view) {
params.cascade = true;
}
var original = {};
for (var key in params) {
@ -1157,15 +1175,13 @@ function loadPartCategoryTable(table, options) {
setupFilterList(filterKey, table, filterListElement);
var tree_view = inventreeLoad('category-tree-view') == 1;
table.inventreeTable({
treeEnable: tree_view,
rootParentId: options.params.parent,
rootParentId: tree_view ? options.params.parent : null,
uniqueId: 'pk',
idField: 'pk',
treeShowField: 'name',
parentIdField: 'parent',
parentIdField: tree_view ? 'parent' : null,
method: 'get',
url: options.url || '{% url "api-part-category-list" %}',
queryParams: filters,
@ -1176,7 +1192,7 @@ function loadPartCategoryTable(table, options) {
name: 'category',
original: original,
showColumns: true,
buttons: [
buttons: options.allowTreeView ? [
{
icon: 'fas fa-bars',
attributes: {
@ -1215,28 +1231,31 @@ function loadPartCategoryTable(table, options) {
);
}
}
],
] : [],
onPostBody: function() {
tree_view = inventreeLoad('category-tree-view') == 1;
if (options.allowTreeView) {
if (tree_view) {
tree_view = inventreeLoad('category-tree-view') == 1;
$('#view-category-list').removeClass('btn-secondary').addClass('btn-outline-secondary');
$('#view-category-tree').removeClass('btn-outline-secondary').addClass('btn-secondary');
table.treegrid({
treeColumn: 0,
onChange: function() {
table.bootstrapTable('resetView');
},
onExpand: function() {
}
});
} else {
$('#view-category-tree').removeClass('btn-secondary').addClass('btn-outline-secondary');
$('#view-category-list').removeClass('btn-outline-secondary').addClass('btn-secondary');
if (tree_view) {
$('#view-category-list').removeClass('btn-secondary').addClass('btn-outline-secondary');
$('#view-category-tree').removeClass('btn-outline-secondary').addClass('btn-secondary');
table.treegrid({
treeColumn: 0,
onChange: function() {
table.bootstrapTable('resetView');
},
onExpand: function() {
}
});
} else {
$('#view-category-tree').removeClass('btn-secondary').addClass('btn-outline-secondary');
$('#view-category-list').removeClass('btn-outline-secondary').addClass('btn-secondary');
}
}
},
columns: [
@ -1253,10 +1272,17 @@ function loadPartCategoryTable(table, options) {
switchable: true,
sortable: true,
formatter: function(value, row) {
return renderLink(
var html = renderLink(
value,
`/part/category/${row.pk}/`
);
if (row.starred) {
html += makeIconBadge('fa-bell icon-green', '{% trans "Subscribed category" %}');
}
return html;
}
},
{

View File

@ -4,9 +4,6 @@
/* globals
attachSelect,
enableField,
clearField,
clearFieldOptions,
closeModal,
constructField,
constructFormBody,
@ -33,10 +30,8 @@
printStockItemLabels,
printTestReports,
renderLink,
reloadFieldOptions,
scanItemsIntoLocation,
showAlertDialog,
setFieldValue,
setupFilterList,
showApiError,
stockStatusDisplay,
@ -44,6 +39,10 @@
/* exported
createNewStockItem,
createStockLocation,
duplicateStockItem,
editStockItem,
editStockLocation,
exportStock,
loadInstalledInTable,
loadStockLocationTable,
@ -51,20 +50,318 @@
loadStockTestResultsTable,
loadStockTrackingTable,
loadTableFilters,
locationFields,
removeStockRow,
serializeStockItem,
stockItemFields,
stockLocationFields,
stockStatusCodes,
*/
function locationFields() {
return {
/*
* Launches a modal form to serialize a particular StockItem
*/
function serializeStockItem(pk, options={}) {
var url = `/api/stock/${pk}/serialize/`;
options.method = 'POST';
options.title = '{% trans "Serialize Stock Item" %}';
options.fields = {
quantity: {},
serial_numbers: {
icon: 'fa-hashtag',
},
destination: {
icon: 'fa-sitemap',
},
notes: {},
};
constructForm(url, options);
}
function stockLocationFields(options={}) {
var fields = {
parent: {
help_text: '{% trans "Parent stock location" %}',
},
name: {},
description: {},
};
if (options.parent) {
fields.parent.value = options.parent;
}
return fields;
}
/*
* Launch an API form to edit a stock location
*/
function editStockLocation(pk, options={}) {
var url = `/api/stock/location/${pk}/`;
options.fields = stockLocationFields(options);
constructForm(url, options);
}
/*
* Launch an API form to create a new stock location
*/
function createStockLocation(options={}) {
var url = '{% url "api-location-list" %}';
options.method = 'POST';
options.fields = stockLocationFields(options);
options.title = '{% trans "New Stock Location" %}';
constructForm(url, options);
}
function stockItemFields(options={}) {
var fields = {
part: {
// Hide the part field unless we are "creating" a new stock item
hidden: !options.create,
onSelect: function(data, field, opts) {
// Callback when a new "part" is selected
// If we are "creating" a new stock item,
// change the available fields based on the part properties
if (options.create) {
// If a "trackable" part is selected, enable serial number field
if (data.trackable) {
enableFormInput('serial_numbers', opts);
// showFormInput('serial_numbers', opts);
} else {
clearFormInput('serial_numbers', opts);
disableFormInput('serial_numbers', opts);
}
// Enable / disable fields based on purchaseable status
if (data.purchaseable) {
enableFormInput('supplier_part', opts);
enableFormInput('purchase_price', opts);
enableFormInput('purchase_price_currency', opts);
} else {
clearFormInput('supplier_part', opts);
clearFormInput('purchase_price', opts);
disableFormInput('supplier_part', opts);
disableFormInput('purchase_price', opts);
disableFormInput('purchase_price_currency', opts);
}
}
}
},
supplier_part: {
icon: 'fa-building',
filters: {
part_detail: true,
supplier_detail: true,
},
adjustFilters: function(query, opts) {
var part = getFormFieldValue('part', {}, opts);
if (part) {
query.part = part;
}
return query;
}
},
location: {
icon: 'fa-sitemap',
},
quantity: {
help_text: '{% trans "Enter initial quantity for this stock item" %}',
},
serial_numbers: {
icon: 'fa-hashtag',
type: 'string',
label: '{% trans "Serial Numbers" %}',
help_text: '{% trans "Enter serial numbers for new stock (or leave blank)" %}',
required: false,
},
serial: {
icon: 'fa-hashtag',
},
status: {},
expiry_date: {},
batch: {},
purchase_price: {
icon: 'fa-dollar-sign',
},
purchase_price_currency: {},
packaging: {
icon: 'fa-box',
},
link: {
icon: 'fa-link',
},
owner: {},
delete_on_deplete: {},
};
if (options.create) {
// Use special "serial numbers" field when creating a new stock item
delete fields['serial'];
} else {
// These fields cannot be edited once the stock item has been created
delete fields['serial_numbers'];
delete fields['quantity'];
delete fields['location'];
}
// Remove stock expiry fields if feature is not enabled
if (!global_settings.STOCK_ENABLE_EXPIRY) {
delete fields['expiry_date'];
}
// Remove ownership field if feature is not enanbled
if (!global_settings.STOCK_OWNERSHIP_CONTROL) {
delete fields['owner'];
}
return fields;
}
function stockItemGroups(options={}) {
return {
};
}
/*
* Launch a modal form to duplicate a given StockItem
*/
function duplicateStockItem(pk, options) {
// First, we need the StockItem informatino
inventreeGet(`/api/stock/${pk}/`, {}, {
success: function(data) {
// Do not duplicate the serial number
delete data['serial'];
options.data = data;
options.create = true;
options.fields = stockItemFields(options);
options.groups = stockItemGroups(options);
options.method = 'POST';
options.title = '{% trans "Duplicate Stock Item" %}';
constructForm('{% url "api-stock-list" %}', options);
}
});
}
/*
* Launch a modal form to edit a given StockItem
*/
function editStockItem(pk, options={}) {
var url = `/api/stock/${pk}/`;
options.create = false;
options.fields = stockItemFields(options);
options.groups = stockItemGroups(options);
options.title = '{% trans "Edit Stock Item" %}';
// Query parameters for retrieving stock item data
options.params = {
part_detail: true,
supplier_part_detail: true,
};
// Augment the rendered form when we receive information about the StockItem
options.processResults = function(data, fields, options) {
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;
}
};
constructForm(url, options);
}
/*
* Launch an API form to contsruct a new stock item
*/
function createNewStockItem(options={}) {
var url = '{% url "api-stock-list" %}';
options.title = '{% trans "New Stock Item" %}';
options.method = 'POST';
options.create = true;
options.fields = stockItemFields(options);
options.groups = stockItemGroups(options);
if (!options.onSuccess) {
options.onSuccess = function(response) {
// If a single stock item has been created, follow it!
if (response.pk) {
var url = `/stock/item/${response.pk}/`;
addCachedAlert('{% trans "Created new stock item" %}', {
icon: 'fas fa-boxes',
});
window.location.href = url;
} else {
// Multiple stock items have been created (i.e. serialized stock)
var details = `
<br>{% trans "Quantity" %}: ${response.quantity}
<br>{% trans "Serial Numbers" %}: ${response.serial_numbers}
`;
showMessage('{% trans "Created multiple stock items" %}', {
icon: 'fas fa-boxes',
details: details,
});
var table = options.table || '#stock-table';
// Reload the table
$(table).bootstrapTable('refresh');
}
};
}
constructForm(url, options);
}
@ -427,7 +724,7 @@ function adjustStock(action, items, options={}) {
break;
default:
$(opts.modal).modal('hide');
showApiError(xhr);
showApiError(xhr, opts.url);
break;
}
}
@ -831,7 +1128,9 @@ function loadStockTable(table, options) {
col = {
field: 'quantity',
sortName: 'stock',
title: '{% trans "Stock" %}',
sortable: true,
formatter: function(value, row) {
var val = parseFloat(value);
@ -1416,13 +1715,22 @@ function loadStockTable(table, options) {
});
}
/*
* Display a table of stock locations
*/
function loadStockLocationTable(table, options) {
/* Display a table of stock locations */
var params = options.params || {};
var filterListElement = options.filterList || '#filter-list-location';
var tree_view = options.allowTreeView && inventreeLoad('location-tree-view') == 1;
if (tree_view) {
params.cascade = true;
}
var filters = {};
var filterKey = options.filterKey || options.name || 'location';
@ -1443,15 +1751,13 @@ function loadStockLocationTable(table, options) {
filters[key] = params[key];
}
var tree_view = inventreeLoad('location-tree-view') == 1;
table.inventreeTable({
treeEnable: tree_view,
rootParentId: options.params.parent,
rootParentId: tree_view ? options.params.parent : null,
uniqueId: 'pk',
idField: 'pk',
treeShowField: 'name',
parentIdField: 'parent',
parentIdField: tree_view ? 'parent' : null,
disablePagination: tree_view,
sidePagination: tree_view ? 'client' : 'server',
serverSort: !tree_view,
@ -1465,28 +1771,31 @@ function loadStockLocationTable(table, options) {
showColumns: true,
onPostBody: function() {
tree_view = inventreeLoad('location-tree-view') == 1;
if (options.allowTreeView) {
if (tree_view) {
tree_view = inventreeLoad('location-tree-view') == 1;
$('#view-location-list').removeClass('btn-secondary').addClass('btn-outline-secondary');
$('#view-location-tree').removeClass('btn-outline-secondary').addClass('btn-secondary');
table.treegrid({
treeColumn: 1,
onChange: function() {
table.bootstrapTable('resetView');
},
onExpand: function() {
}
});
} else {
$('#view-location-tree').removeClass('btn-secondary').addClass('btn-outline-secondary');
$('#view-location-list').removeClass('btn-outline-secondary').addClass('btn-secondary');
if (tree_view) {
$('#view-location-list').removeClass('btn-secondary').addClass('btn-outline-secondary');
$('#view-location-tree').removeClass('btn-outline-secondary').addClass('btn-secondary');
table.treegrid({
treeColumn: 1,
onChange: function() {
table.bootstrapTable('resetView');
},
onExpand: function() {
}
});
} else {
$('#view-location-tree').removeClass('btn-secondary').addClass('btn-outline-secondary');
$('#view-location-list').removeClass('btn-outline-secondary').addClass('btn-secondary');
}
}
},
buttons: [
buttons: options.allowTreeView ? [
{
icon: 'fas fa-bars',
attributes: {
@ -1525,7 +1834,7 @@ function loadStockLocationTable(table, options) {
);
}
}
],
] : [],
columns: [
{
checkbox: true,
@ -1800,79 +2109,6 @@ function loadStockTrackingTable(table, options) {
}
function createNewStockItem(options) {
/* Launch a modal form to create a new stock item.
*
* This is really just a helper function which calls launchModalForm,
* but it does get called a lot, so here we are ...
*/
// Add in some funky options
options.callback = [
{
field: 'part',
action: function(value) {
if (!value) {
// No part chosen
clearFieldOptions('supplier_part');
enableField('serial_numbers', false);
enableField('purchase_price_0', false);
enableField('purchase_price_1', false);
return;
}
// Reload options for supplier part
reloadFieldOptions(
'supplier_part',
{
url: '{% url "api-supplier-part-list" %}',
params: {
part: value,
pretty: true,
},
text: function(item) {
return item.pretty_name;
}
}
);
// Request part information from the server
inventreeGet(
`/api/part/${value}/`, {},
{
success: function(response) {
// Disable serial number field if the part is not trackable
enableField('serial_numbers', response.trackable);
clearField('serial_numbers');
enableField('purchase_price_0', response.purchaseable);
enableField('purchase_price_1', response.purchaseable);
// Populate the expiry date
if (response.default_expiry <= 0) {
// No expiry date
clearField('expiry_date');
} else {
var expiry = moment().add(response.default_expiry, 'days');
setFieldValue('expiry_date', expiry.format('YYYY-MM-DD'));
}
}
}
);
}
},
];
launchModalForm('{% url "stock-item-create" %}', options);
}
function loadInstalledInTable(table, options) {
/*
* Display a table showing the stock items which are installed in this stock item.

View File

@ -103,6 +103,10 @@ function getAvailableTableFilters(tableKey) {
title: '{% trans "Include subcategories" %}',
description: '{% trans "Include subcategories" %}',
},
starred: {
type: 'bool',
title: '{% trans "Subscribed" %}',
},
};
}
@ -368,7 +372,7 @@ function getAvailableTableFilters(tableKey) {
},
starred: {
type: 'bool',
title: '{% trans "Starred" %}',
title: '{% trans "Subscribed" %}',
},
salable: {
type: 'bool',