mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	Updates to StockOperationsRow (#7182)
- Allow custom parameters to be passed - Add memo
This commit is contained in:
		| @@ -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 ? ( | ||||
|     <div>{t`Loading...`}</div> | ||||
|   ) : ( | ||||
|     <tr> | ||||
|       <td> | ||||
|         <Flex gap="sm" align="center"> | ||||
|           <Thumbnail | ||||
|             size={40} | ||||
|             src={record.part_detail.thumbnail} | ||||
|             src={record.part_detail?.thumbnail} | ||||
|             align="center" | ||||
|           /> | ||||
|           <div>{record.part_detail.name}</div> | ||||
|           <div>{record.part_detail?.name}</div> | ||||
|         </Flex> | ||||
|       </td> | ||||
|       <td>{record.location ? record.location_detail.pathstring : '-'}</td> | ||||
|       <td>{record.location ? record.location_detail?.pathstring : '-'}</td> | ||||
|       <td> | ||||
|         <Flex align="center" gap="xs"> | ||||
|           <Group position="apart"> | ||||
| @@ -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; | ||||
| }; | ||||
|   | ||||
| @@ -704,7 +704,10 @@ export default function PartDetail() { | ||||
|     return { | ||||
|       pk: part.pk, | ||||
|       model: ModelType.part, | ||||
|       refresh: refreshInstance | ||||
|       refresh: refreshInstance, | ||||
|       filters: { | ||||
|         in_stock: true | ||||
|       } | ||||
|     }; | ||||
|   }, [part]); | ||||
|  | ||||
|   | ||||
| @@ -200,7 +200,10 @@ export default function Stock() { | ||||
|     return { | ||||
|       pk: location.pk, | ||||
|       model: 'location', | ||||
|       refresh: refreshInstance | ||||
|       refresh: refreshInstance, | ||||
|       filters: { | ||||
|         in_stock: true | ||||
|       } | ||||
|     }; | ||||
|   }, [location]); | ||||
|  | ||||
|   | ||||
| @@ -374,7 +374,10 @@ export default function StockDetail() { | ||||
|     return { | ||||
|       items: stockitem, | ||||
|       model: ModelType.stockitem, | ||||
|       refresh: refreshInstance | ||||
|       refresh: refreshInstance, | ||||
|       filters: { | ||||
|         in_stock: true | ||||
|       } | ||||
|     }; | ||||
|   }, [stockitem]); | ||||
|  | ||||
|   | ||||
| @@ -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]); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user