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={}) {
|
function clearField(fieldName, options={}) {
|
||||||
|
|
||||||
|
setFieldValue(fieldName, '', options);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setFieldValue(fieldName, value, options={}) {
|
||||||
|
|
||||||
var modal = options.modal || '#modal-form';
|
var modal = options.modal || '#modal-form';
|
||||||
|
|
||||||
var field = getFieldByName(modal, fieldName);
|
var field = getFieldByName(modal, fieldName);
|
||||||
|
|
||||||
field.val("");
|
field.val(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -289,6 +289,7 @@ class PartSerializer(InvenTreeModelSerializer):
|
|||||||
'component',
|
'component',
|
||||||
'description',
|
'description',
|
||||||
'default_location',
|
'default_location',
|
||||||
|
'default_expiry',
|
||||||
'full_name',
|
'full_name',
|
||||||
'image',
|
'image',
|
||||||
'in_stock',
|
'in_stock',
|
||||||
|
@ -618,8 +618,8 @@ function loadStockTable(table, options) {
|
|||||||
if (action == 'move') {
|
if (action == 'move') {
|
||||||
secondary.push({
|
secondary.push({
|
||||||
field: 'destination',
|
field: 'destination',
|
||||||
label: 'New Location',
|
label: '{% trans "New Location" %}',
|
||||||
title: 'Create new location',
|
title: '{% trans "Create new location" %}',
|
||||||
url: "/stock/location/new/",
|
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(
|
inventreeGet(
|
||||||
`/api/part/${value}/`, {},
|
`/api/part/${value}/`, {},
|
||||||
{
|
{
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
|
|
||||||
|
// Disable serial number field if the part is not trackable
|
||||||
enableField('serial_numbers', response.trackable);
|
enableField('serial_numbers', response.trackable);
|
||||||
clearField('serial_numbers');
|
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