Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PUI] Fix stock actions #8569

Merged
merged 5 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions src/frontend/src/forms/StockForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ function stockOperationModal({
endpoint,
filters,
title,
successMessage,
modalFunc = useCreateApiFormModal
}: {
items?: object;
Expand All @@ -880,6 +881,7 @@ function stockOperationModal({
fieldGenerator: (items: any[]) => ApiFormFieldSet;
endpoint: ApiEndpoints;
title: string;
successMessage?: string;
modalFunc?: apiModalFunc;
}) {
const baseParams: any = {
Expand Down Expand Up @@ -932,12 +934,13 @@ function stockOperationModal({
fields: fields,
title: title,
size: '80%',
successMessage: successMessage,
onFormSuccess: () => refresh()
});
}

export type StockOperationProps = {
items?: object;
items?: any[];
pk?: number;
filters?: any;
model: ModelType.stockitem | 'location' | ModelType.part;
Expand All @@ -949,7 +952,8 @@ export function useAddStockItem(props: StockOperationProps) {
...props,
fieldGenerator: stockAddFields,
endpoint: ApiEndpoints.stock_add,
title: t`Add Stock`
title: t`Add Stock`,
successMessage: t`Stock added`
});
}

Expand All @@ -958,7 +962,8 @@ export function useRemoveStockItem(props: StockOperationProps) {
...props,
fieldGenerator: stockRemoveFields,
endpoint: ApiEndpoints.stock_remove,
title: t`Remove Stock`
title: t`Remove Stock`,
successMessage: t`Stock removed`
});
}

Expand All @@ -967,7 +972,8 @@ export function useTransferStockItem(props: StockOperationProps) {
...props,
fieldGenerator: stockTransferFields,
endpoint: ApiEndpoints.stock_transfer,
title: t`Transfer Stock`
title: t`Transfer Stock`,
successMessage: t`Stock transferred`
});
}

Expand All @@ -976,7 +982,8 @@ export function useCountStockItem(props: StockOperationProps) {
...props,
fieldGenerator: stockCountFields,
endpoint: ApiEndpoints.stock_count,
title: t`Count Stock`
title: t`Count Stock`,
successMessage: t`Stock counted`
});
}

Expand All @@ -985,7 +992,8 @@ export function useChangeStockStatus(props: StockOperationProps) {
...props,
fieldGenerator: stockChangeStatusFields,
endpoint: ApiEndpoints.stock_change_status,
title: t`Change Stock Status`
title: t`Change Stock Status`,
successMessage: t`Stock status changed`
});
}

Expand All @@ -994,16 +1002,24 @@ export function useMergeStockItem(props: StockOperationProps) {
...props,
fieldGenerator: stockMergeFields,
endpoint: ApiEndpoints.stock_merge,
title: t`Merge Stock`
title: t`Merge Stock`,
successMessage: t`Stock merged`
});
}

export function useAssignStockItem(props: StockOperationProps) {
// Filter items - only allow 'salable' items
const items = useMemo(() => {
return props.items?.filter((item) => item?.part_detail?.salable);
}, [props.items]);

return stockOperationModal({
...props,
items: items,
fieldGenerator: stockAssignFields,
endpoint: ApiEndpoints.stock_assign,
title: t`Assign Stock to Customer`
title: t`Assign Stock to Customer`,
successMessage: t`Stock assigned to customer`
});
}

Expand All @@ -1013,7 +1029,8 @@ export function useDeleteStockItem(props: StockOperationProps) {
fieldGenerator: stockDeleteFields,
endpoint: ApiEndpoints.stock_item_list,
modalFunc: useDeleteApiFormModal,
title: t`Delete Stock Items`
title: t`Delete Stock Items`,
successMessage: t`Stock deleted`
});
}

Expand Down
18 changes: 16 additions & 2 deletions src/frontend/src/pages/stock/StockDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { UserRoles } from '../../enums/Roles';
import {
type StockOperationProps,
useAddStockItem,
useAssignStockItem,
useCountStockItem,
useRemoveStockItem,
useStockFields,
Expand Down Expand Up @@ -588,7 +589,7 @@ export default function StockDetail() {

const stockActionProps: StockOperationProps = useMemo(() => {
return {
items: stockitem,
items: [stockitem],
model: ModelType.stockitem,
refresh: refreshInstance,
filters: {
Expand All @@ -601,6 +602,7 @@ export default function StockDetail() {
const addStockItem = useAddStockItem(stockActionProps);
const removeStockItem = useRemoveStockItem(stockActionProps);
const transferStockItem = useTransferStockItem(stockActionProps);
const assignToCustomer = useAssignStockItem(stockActionProps);

const serializeStockFields = useStockItemSerializeFields({
partId: stockitem.part,
Expand Down Expand Up @@ -731,7 +733,7 @@ export default function StockDetail() {
{
name: t`Return`,
tooltip: t`Return from customer`,
hidden: !stockitem.sales_order,
hidden: !stockitem.customer,
icon: (
<InvenTreeIcon
icon='return_orders'
Expand All @@ -741,6 +743,17 @@ export default function StockDetail() {
onClick: () => {
stockitem.pk && returnStockItem.open();
}
},
{
name: t`Assign to Customer`,
tooltip: t`Assign to a customer`,
hidden: !!stockitem.customer,
icon: (
<InvenTreeIcon icon='customer' iconProps={{ color: 'blue' }} />
),
onClick: () => {
stockitem.pk && assignToCustomer.open();
}
}
]}
/>,
Expand Down Expand Up @@ -874,6 +887,7 @@ export default function StockDetail() {
{transferStockItem.modal}
{serializeStockItem.modal}
{returnStockItem.modal}
{assignToCustomer.modal}
</Stack>
</InstanceDetail>
);
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/tables/stock/StockItemTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ export function StockItemTable({
{
name: t`Assign to customer`,
icon: <InvenTreeIcon icon='customer' />,
tooltip: t`Order new stock`,
tooltip: t`Assign items to a customer`,
disabled: !can_add_stock,
onClick: () => {
assignStock.open();
Expand Down
Loading