Auto-update the expiry date in the StockItem form when switching Part selection

This commit is contained in:
Oliver Walters 2021-01-05 00:37:42 +11:00
parent 9dc9c0fcb7
commit 9a30108b75
3 changed files with 22 additions and 5 deletions

View File

@ -151,12 +151,17 @@ function enableField(fieldName, enabled, options={}) {
}
function clearField(fieldName, options={}) {
setFieldValue(fieldName, '', options);
}
function setFieldValue(fieldName, value, options={}) {
var modal = options.modal || '#modal-form';
var field = getFieldByName(modal, fieldName);
field.val("");
field.val(value);
}

View File

@ -289,6 +289,7 @@ class PartSerializer(InvenTreeModelSerializer):
'component',
'description',
'default_location',
'default_expiry',
'full_name',
'image',
'in_stock',

View File

@ -618,8 +618,8 @@ function loadStockTable(table, options) {
if (action == 'move') {
secondary.push({
field: 'destination',
label: 'New Location',
title: 'Create new location',
label: '{% trans "New Location" %}',
title: '{% trans "Create new location" %}',
url: "/stock/location/new/",
});
}
@ -837,14 +837,25 @@ function createNewStockItem(options) {
}
);
// Disable serial number field if the part is not trackable
// 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');
// 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"));
}
}
}
);