mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 12:05:53 +00:00
Add Expiry Date on Receive Line Item (#8867)
* Add expiry on line item receive from PO * add backend test * reset pre-commit * increment inventree api version * use None as default expiry date * check global setting STOCK_ENABLE_EXPIRY * check for default expiry in line item receive * use dayjs --------- Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
@ -25,6 +25,8 @@ import {
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { IconCalendarExclamation } from '@tabler/icons-react';
|
||||
import dayjs from 'dayjs';
|
||||
import { api } from '../App';
|
||||
import { ActionButton } from '../components/buttons/ActionButton';
|
||||
import RemoveRowButton from '../components/buttons/RemoveRowButton';
|
||||
@ -49,7 +51,7 @@ import {
|
||||
useSerialNumberGenerator
|
||||
} from '../hooks/UseGenerator';
|
||||
import { apiUrl } from '../states/ApiState';
|
||||
|
||||
import { useGlobalSettingsState } from '../states/SettingsState';
|
||||
/*
|
||||
* Construct a set of fields for creating / editing a PurchaseOrderLineItem instance
|
||||
*/
|
||||
@ -246,6 +248,8 @@ function LineItemFormRow({
|
||||
[record]
|
||||
);
|
||||
|
||||
const settings = useGlobalSettingsState();
|
||||
|
||||
useEffect(() => {
|
||||
if (!!record.destination) {
|
||||
props.changeFn(props.idx, 'location', record.destination);
|
||||
@ -298,6 +302,23 @@ function LineItemFormRow({
|
||||
}
|
||||
});
|
||||
|
||||
const [expiryDateOpen, expiryDateHandlers] = useDisclosure(false, {
|
||||
onOpen: () => {
|
||||
// check the default part expiry. Assume expiry is relative to today
|
||||
const defaultExpiry = record.part_detail?.default_expiry;
|
||||
if (defaultExpiry !== undefined && defaultExpiry > 0) {
|
||||
props.changeFn(
|
||||
props.idx,
|
||||
'expiry_date',
|
||||
dayjs().add(defaultExpiry, 'day').format('YYYY-MM-DD')
|
||||
);
|
||||
}
|
||||
},
|
||||
onClose: () => {
|
||||
props.changeFn(props.idx, 'expiry_date', undefined);
|
||||
}
|
||||
});
|
||||
|
||||
// Status value
|
||||
const [statusOpen, statusHandlers] = useDisclosure(false, {
|
||||
onClose: () => props.changeFn(props.idx, 'status', undefined)
|
||||
@ -440,6 +461,16 @@ function LineItemFormRow({
|
||||
tooltipAlignment='top'
|
||||
variant={batchOpen ? 'filled' : 'transparent'}
|
||||
/>
|
||||
{settings.isSet('STOCK_ENABLE_EXPIRY') && (
|
||||
<ActionButton
|
||||
size='sm'
|
||||
onClick={() => expiryDateHandlers.toggle()}
|
||||
icon={<IconCalendarExclamation />}
|
||||
tooltip={t`Set Expiry Date`}
|
||||
tooltipAlignment='top'
|
||||
variant={expiryDateOpen ? 'filled' : 'transparent'}
|
||||
/>
|
||||
)}
|
||||
<ActionButton
|
||||
size='sm'
|
||||
icon={<InvenTreeIcon icon='packaging' />}
|
||||
@ -586,6 +617,21 @@ function LineItemFormRow({
|
||||
}}
|
||||
error={props.rowErrors?.serial_numbers?.message}
|
||||
/>
|
||||
{settings.isSet('STOCK_ENABLE_EXPIRY') && (
|
||||
<TableFieldExtraRow
|
||||
visible={expiryDateOpen}
|
||||
onValueChange={(value) =>
|
||||
props.changeFn(props.idx, 'expiry_date', value)
|
||||
}
|
||||
fieldDefinition={{
|
||||
field_type: 'date',
|
||||
label: t`Expiry Date`,
|
||||
description: t`Enter an expiry date for received items`,
|
||||
value: props.item.expiry_date
|
||||
}}
|
||||
error={props.rowErrors?.expiry_date?.message}
|
||||
/>
|
||||
)}
|
||||
<TableFieldExtraRow
|
||||
visible={packagingOpen}
|
||||
onValueChange={(value) => props.changeFn(props.idx, 'packaging', value)}
|
||||
@ -672,6 +718,7 @@ export function useReceiveLineItems(props: LineItemsForm) {
|
||||
line_item: elem.pk,
|
||||
location: elem.destination ?? elem.destination_detail?.pk ?? null,
|
||||
quantity: elem.quantity - elem.received,
|
||||
expiry_date: null,
|
||||
batch_code: '',
|
||||
serial_numbers: '',
|
||||
status: 10,
|
||||
|
Reference in New Issue
Block a user