mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Auto-update the expiry date in the StockItem form when switching Part selection
This commit is contained in:
parent
9dc9c0fcb7
commit
9a30108b75
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -289,6 +289,7 @@ class PartSerializer(InvenTreeModelSerializer):
|
||||
'component',
|
||||
'description',
|
||||
'default_location',
|
||||
'default_expiry',
|
||||
'full_name',
|
||||
'image',
|
||||
'in_stock',
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user