mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
parent
c99aae5a28
commit
000419255a
@ -68,6 +68,8 @@ export function useStockFields({
|
|||||||
const [nextBatchCode, setNextBatchCode] = useState<string>('');
|
const [nextBatchCode, setNextBatchCode] = useState<string>('');
|
||||||
const [nextSerialNumber, setNextSerialNumber] = useState<string>('');
|
const [nextSerialNumber, setNextSerialNumber] = useState<string>('');
|
||||||
|
|
||||||
|
const [expiryDate, setExpiryDate] = useState<string | null>(null);
|
||||||
|
|
||||||
const batchGenerator = useBatchCodeGenerator((value: any) => {
|
const batchGenerator = useBatchCodeGenerator((value: any) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
setNextBatchCode(`${t`Next batch code`}: ${value}`);
|
setNextBatchCode(`${t`Next batch code`}: ${value}`);
|
||||||
@ -106,6 +108,18 @@ export function useStockFields({
|
|||||||
|
|
||||||
// Clear the 'supplier_part' field if the part is changed
|
// Clear the 'supplier_part' field if the part is changed
|
||||||
setSupplierPart(null);
|
setSupplierPart(null);
|
||||||
|
|
||||||
|
// Adjust the 'expiry date' for the stock item
|
||||||
|
const expiry_days = record?.default_expiry ?? 0;
|
||||||
|
|
||||||
|
if (expiry_days && expiry_days > 0) {
|
||||||
|
// Adjust the expiry date based on the part default expiry
|
||||||
|
setExpiryDate(
|
||||||
|
new Date(
|
||||||
|
new Date().getTime() + expiry_days * 24 * 60 * 60 * 1000
|
||||||
|
).toISOString()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
supplier_part: {
|
supplier_part: {
|
||||||
@ -171,7 +185,11 @@ export function useStockFields({
|
|||||||
},
|
},
|
||||||
expiry_date: {
|
expiry_date: {
|
||||||
icon: <IconCalendarExclamation />,
|
icon: <IconCalendarExclamation />,
|
||||||
hidden: !globalSettings.isSet('STOCK_ENABLE_EXPIRY')
|
hidden: !globalSettings.isSet('STOCK_ENABLE_EXPIRY'),
|
||||||
|
value: expiryDate,
|
||||||
|
onValueChange: (value) => {
|
||||||
|
setExpiryDate(value);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
purchase_price: {
|
purchase_price: {
|
||||||
icon: <IconCurrencyDollar />
|
icon: <IconCurrencyDollar />
|
||||||
@ -194,9 +212,15 @@ export function useStockFields({
|
|||||||
// TODO: Handle custom field management based on provided options
|
// TODO: Handle custom field management based on provided options
|
||||||
// TODO: refer to stock.py in original codebase
|
// TODO: refer to stock.py in original codebase
|
||||||
|
|
||||||
|
// Remove the expiry date field if it is not enabled
|
||||||
|
if (!globalSettings.isSet('STOCK_ENABLE_EXPIRY')) {
|
||||||
|
delete fields.expiry_date;
|
||||||
|
}
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
}, [
|
}, [
|
||||||
stockItem,
|
stockItem,
|
||||||
|
expiryDate,
|
||||||
partInstance,
|
partInstance,
|
||||||
partId,
|
partId,
|
||||||
globalSettings,
|
globalSettings,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user