2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-01 04:56:45 +00:00

Updates to StockOperationsRow (#7182)

- Allow custom parameters to be passed
- Add memo
This commit is contained in:
Oliver 2024-05-08 14:38:35 +10:00 committed by GitHub
parent d16ee6755e
commit 6d620c713a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 44 additions and 14 deletions

View File

@ -283,6 +283,10 @@ function StockOperationsRow({
}; };
const stockString: string = useMemo(() => { const stockString: string = useMemo(() => {
if (!record) {
return '-';
}
if (!record.serial) { if (!record.serial) {
return `${record.quantity}`; return `${record.quantity}`;
} else { } else {
@ -290,19 +294,21 @@ function StockOperationsRow({
} }
}, [record]); }, [record]);
return ( return !record ? (
<div>{t`Loading...`}</div>
) : (
<tr> <tr>
<td> <td>
<Flex gap="sm" align="center"> <Flex gap="sm" align="center">
<Thumbnail <Thumbnail
size={40} size={40}
src={record.part_detail.thumbnail} src={record.part_detail?.thumbnail}
align="center" align="center"
/> />
<div>{record.part_detail.name}</div> <div>{record.part_detail?.name}</div>
</Flex> </Flex>
</td> </td>
<td>{record.location ? record.location_detail.pathstring : '-'}</td> <td>{record.location ? record.location_detail?.pathstring : '-'}</td>
<td> <td>
<Flex align="center" gap="xs"> <Flex align="center" gap="xs">
<Group position="apart"> <Group position="apart">
@ -332,8 +338,8 @@ function StockOperationsRow({
tooltip={t`Move to default location`} tooltip={t`Move to default location`}
tooltipAlignment="top" tooltipAlignment="top"
disabled={ disabled={
!record.part_detail.default_location && !record.part_detail?.default_location &&
!record.part_detail.category_default_location !record.part_detail?.category_default_location
} }
/> />
)} )}
@ -653,11 +659,13 @@ function stockOperationModal({
refresh, refresh,
fieldGenerator, fieldGenerator,
endpoint, endpoint,
filters,
title, title,
modalFunc = useCreateApiFormModal modalFunc = useCreateApiFormModal
}: { }: {
items?: object; items?: object;
pk?: number; pk?: number;
filters?: any;
model: ModelType | string; model: ModelType | string;
refresh: () => void; refresh: () => void;
fieldGenerator: (items: any[]) => ApiFormFieldSet; fieldGenerator: (items: any[]) => ApiFormFieldSet;
@ -665,17 +673,26 @@ function stockOperationModal({
title: string; title: string;
modalFunc?: apiModalFunc; modalFunc?: apiModalFunc;
}) { }) {
const params: any = { const baseParams: any = {
part_detail: true, part_detail: true,
location_detail: true, location_detail: true,
cascade: false cascade: false
}; };
// A Stock item can have location=null, but not part=null const params = useMemo(() => {
params[model] = pk === undefined && model === 'location' ? 'null' : pk; let query_params: any = {
...baseParams,
...(filters ?? {})
};
query_params[model] =
pk === undefined && model === 'location' ? 'null' : pk;
return query_params;
}, [baseParams, filters, model, pk]);
const { data } = useQuery({ const { data } = useQuery({
queryKey: ['stockitems', model, pk, items], queryKey: ['stockitems', model, pk, items, params],
queryFn: async () => { queryFn: async () => {
if (items) { if (items) {
return Array.isArray(items) ? items : [items]; return Array.isArray(items) ? items : [items];
@ -712,6 +729,7 @@ function stockOperationModal({
export type StockOperationProps = { export type StockOperationProps = {
items?: object; items?: object;
pk?: number; pk?: number;
filters?: any;
model: ModelType.stockitem | 'location' | ModelType.part; model: ModelType.stockitem | 'location' | ModelType.part;
refresh: () => void; refresh: () => void;
}; };

View File

@ -704,7 +704,10 @@ export default function PartDetail() {
return { return {
pk: part.pk, pk: part.pk,
model: ModelType.part, model: ModelType.part,
refresh: refreshInstance refresh: refreshInstance,
filters: {
in_stock: true
}
}; };
}, [part]); }, [part]);

View File

@ -200,7 +200,10 @@ export default function Stock() {
return { return {
pk: location.pk, pk: location.pk,
model: 'location', model: 'location',
refresh: refreshInstance refresh: refreshInstance,
filters: {
in_stock: true
}
}; };
}, [location]); }, [location]);

View File

@ -374,7 +374,10 @@ export default function StockDetail() {
return { return {
items: stockitem, items: stockitem,
model: ModelType.stockitem, model: ModelType.stockitem,
refresh: refreshInstance refresh: refreshInstance,
filters: {
in_stock: true
}
}; };
}, [stockitem]); }, [stockitem]);

View File

@ -368,7 +368,10 @@ export function StockItemTable({
return { return {
items: table.selectedRecords, items: table.selectedRecords,
model: ModelType.stockitem, model: ModelType.stockitem,
refresh: table.refreshTable refresh: table.refreshTable,
filters: {
in_stock: true
}
}; };
}, [table]); }, [table]);