2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-02 03:30:54 +00:00

More fixes

- Allow stock item creation for inactive parts
- Better handling of successful stock item creation
- Disable fields rather than hiding them
This commit is contained in:
Oliver
2021-11-05 00:02:55 +11:00
parent b41dbba2b0
commit f27acde934
7 changed files with 73 additions and 22 deletions

View File

@ -25,6 +25,9 @@
*/
/* exported
clearFormInput,
disableFormInput,
enableFormInput,
hideFormInput,
setFormGroupVisibility,
showFormInput,
@ -1261,6 +1264,23 @@ 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();

View File

@ -138,20 +138,33 @@ function stockItemFields(options={}) {
onSelect: function(data, field, opts) {
// Callback when a new "part" is selected
// If we are "creating" a new stock item
// 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) {
showFormInput('serial_numbers', opts);
enableFormInput('serial_numbers', opts);
// showFormInput('serial_numbers', opts);
} else {
updateFieldValue('serial_numbers', '', {}, opts);
hideFormInput('serial_numbers', opts);
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);
}
}
// TODO: Hide "purchase price" fields for non purchaseable parts!
// TODO: Update "location" based on "default_location" returned
}
},
supplier_part: {
@ -204,7 +217,7 @@ function stockItemFields(options={}) {
};
if (options.create) {
// Use "serial numbers" field when creating a new stock item
// 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
@ -321,25 +334,28 @@ function createNewStockItem(options={}) {
options.onSuccess = function(response) {
// If a single stock item has been created, follow it!
if (response.pk) {
var url = `/stock/item/${pk}/`;
var url = `/stock/item/${response.pk}/`;
addCachedAlert('{% trans "Created stock item" %}', {
addCachedAlert('{% trans "Created new stock item" %}', {
icon: 'fas fa-boxes',
});
location.href = url;
window.location.href = url;
} else {
// Multiple stock items have been created (i.e. serialized stock)
var q = response.quantity;
showMessage('{% trans "Created stock items" %}', {
showMessage('{% trans "Created multiple stock items" %}', {
icon: 'fas fa-boxes',
details: `{% trans "Serial numbers" %}: ${response.serial_numbers}`
});
if (options.table) {
// Reload the table
$(options.table).bootstrapTable('refresh');
}
var table = options.table || '#stock-table';
// Reload the table
$(table).bootstrapTable('refresh');
}
}
}