diff --git a/src/frontend/src/forms/StockForms.tsx b/src/frontend/src/forms/StockForms.tsx
index 418c09112c..d7af1e4659 100644
--- a/src/frontend/src/forms/StockForms.tsx
+++ b/src/frontend/src/forms/StockForms.tsx
@@ -283,6 +283,10 @@ function StockOperationsRow({
};
const stockString: string = useMemo(() => {
+ if (!record) {
+ return '-';
+ }
+
if (!record.serial) {
return `${record.quantity}`;
} else {
@@ -290,19 +294,21 @@ function StockOperationsRow({
}
}, [record]);
- return (
+ return !record ? (
+
- {record.part_detail.name}
+ {record.part_detail?.name}
|
- {record.location ? record.location_detail.pathstring : '-'} |
+ {record.location ? record.location_detail?.pathstring : '-'} |
@@ -332,8 +338,8 @@ function StockOperationsRow({
tooltip={t`Move to default location`}
tooltipAlignment="top"
disabled={
- !record.part_detail.default_location &&
- !record.part_detail.category_default_location
+ !record.part_detail?.default_location &&
+ !record.part_detail?.category_default_location
}
/>
)}
@@ -653,11 +659,13 @@ function stockOperationModal({
refresh,
fieldGenerator,
endpoint,
+ filters,
title,
modalFunc = useCreateApiFormModal
}: {
items?: object;
pk?: number;
+ filters?: any;
model: ModelType | string;
refresh: () => void;
fieldGenerator: (items: any[]) => ApiFormFieldSet;
@@ -665,17 +673,26 @@ function stockOperationModal({
title: string;
modalFunc?: apiModalFunc;
}) {
- const params: any = {
+ const baseParams: any = {
part_detail: true,
location_detail: true,
cascade: false
};
- // A Stock item can have location=null, but not part=null
- params[model] = pk === undefined && model === 'location' ? 'null' : pk;
+ const params = useMemo(() => {
+ 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({
- queryKey: ['stockitems', model, pk, items],
+ queryKey: ['stockitems', model, pk, items, params],
queryFn: async () => {
if (items) {
return Array.isArray(items) ? items : [items];
@@ -712,6 +729,7 @@ function stockOperationModal({
export type StockOperationProps = {
items?: object;
pk?: number;
+ filters?: any;
model: ModelType.stockitem | 'location' | ModelType.part;
refresh: () => void;
};
diff --git a/src/frontend/src/pages/part/PartDetail.tsx b/src/frontend/src/pages/part/PartDetail.tsx
index f897658890..8521ae9d03 100644
--- a/src/frontend/src/pages/part/PartDetail.tsx
+++ b/src/frontend/src/pages/part/PartDetail.tsx
@@ -704,7 +704,10 @@ export default function PartDetail() {
return {
pk: part.pk,
model: ModelType.part,
- refresh: refreshInstance
+ refresh: refreshInstance,
+ filters: {
+ in_stock: true
+ }
};
}, [part]);
diff --git a/src/frontend/src/pages/stock/LocationDetail.tsx b/src/frontend/src/pages/stock/LocationDetail.tsx
index e69a6603cf..c96630c90b 100644
--- a/src/frontend/src/pages/stock/LocationDetail.tsx
+++ b/src/frontend/src/pages/stock/LocationDetail.tsx
@@ -200,7 +200,10 @@ export default function Stock() {
return {
pk: location.pk,
model: 'location',
- refresh: refreshInstance
+ refresh: refreshInstance,
+ filters: {
+ in_stock: true
+ }
};
}, [location]);
diff --git a/src/frontend/src/pages/stock/StockDetail.tsx b/src/frontend/src/pages/stock/StockDetail.tsx
index 31a3f3b3dc..14badedabb 100644
--- a/src/frontend/src/pages/stock/StockDetail.tsx
+++ b/src/frontend/src/pages/stock/StockDetail.tsx
@@ -374,7 +374,10 @@ export default function StockDetail() {
return {
items: stockitem,
model: ModelType.stockitem,
- refresh: refreshInstance
+ refresh: refreshInstance,
+ filters: {
+ in_stock: true
+ }
};
}, [stockitem]);
diff --git a/src/frontend/src/tables/stock/StockItemTable.tsx b/src/frontend/src/tables/stock/StockItemTable.tsx
index 67165aa5b0..19a22112b2 100644
--- a/src/frontend/src/tables/stock/StockItemTable.tsx
+++ b/src/frontend/src/tables/stock/StockItemTable.tsx
@@ -368,7 +368,10 @@ export function StockItemTable({
return {
items: table.selectedRecords,
model: ModelType.stockitem,
- refresh: table.refreshTable
+ refresh: table.refreshTable,
+ filters: {
+ in_stock: true
+ }
};
}, [table]);
|