mirror of
https://github.com/inventree/InvenTree.git
synced 2025-11-30 01:10:00 +00:00
Check / uncheck shipments from table (#10907)
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
import { t } from '@lingui/core/macro';
|
import { t } from '@lingui/core/macro';
|
||||||
import { Table } from '@mantine/core';
|
import { Alert, Table, Text } from '@mantine/core';
|
||||||
import {
|
import {
|
||||||
IconAddressBook,
|
IconAddressBook,
|
||||||
IconCalendar,
|
IconCalendar,
|
||||||
|
IconCircleCheck,
|
||||||
|
IconCircleX,
|
||||||
IconCoins,
|
IconCoins,
|
||||||
IconUser,
|
IconUser,
|
||||||
IconUsers
|
IconUsers
|
||||||
@@ -23,8 +25,9 @@ import type {
|
|||||||
ApiFormFieldType
|
ApiFormFieldType
|
||||||
} from '@lib/types/Forms';
|
} from '@lib/types/Forms';
|
||||||
import type { TableFieldRowProps } from '../components/forms/fields/TableField';
|
import type { TableFieldRowProps } from '../components/forms/fields/TableField';
|
||||||
import { useCreateApiFormModal } from '../hooks/UseForm';
|
import { useCreateApiFormModal, useEditApiFormModal } from '../hooks/UseForm';
|
||||||
import { useGlobalSettingsState } from '../states/SettingsStates';
|
import { useGlobalSettingsState } from '../states/SettingsStates';
|
||||||
|
import { useUserState } from '../states/UserState';
|
||||||
import { RenderPartColumn } from '../tables/ColumnRenderers';
|
import { RenderPartColumn } from '../tables/ColumnRenderers';
|
||||||
|
|
||||||
export function useSalesOrderFields({
|
export function useSalesOrderFields({
|
||||||
@@ -190,6 +193,64 @@ export function useSalesOrderLineItemFields({
|
|||||||
}, [salePrice, partCurrency, orderId, create]);
|
}, [salePrice, partCurrency, orderId, create]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useCheckShipmentForm({
|
||||||
|
shipmentId,
|
||||||
|
onSuccess
|
||||||
|
}: {
|
||||||
|
shipmentId: number;
|
||||||
|
onSuccess: (response: any) => void;
|
||||||
|
}) {
|
||||||
|
const user = useUserState();
|
||||||
|
|
||||||
|
return useEditApiFormModal({
|
||||||
|
url: ApiEndpoints.sales_order_shipment_list,
|
||||||
|
pk: shipmentId,
|
||||||
|
title: t`Check Shipment`,
|
||||||
|
preFormContent: (
|
||||||
|
<Alert color='green' icon={<IconCircleCheck />} title={t`Check Shipment`}>
|
||||||
|
<Text>{t`Marking the shipment as checked indicates that you have verified that all items included in this shipment are correct`}</Text>
|
||||||
|
</Alert>
|
||||||
|
),
|
||||||
|
fetchInitialData: false,
|
||||||
|
fields: {
|
||||||
|
checked_by: {
|
||||||
|
hidden: true,
|
||||||
|
value: user.getUser()?.pk
|
||||||
|
}
|
||||||
|
},
|
||||||
|
successMessage: t`Shipment marked as checked`,
|
||||||
|
onFormSuccess: onSuccess
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUncheckShipmentForm({
|
||||||
|
shipmentId,
|
||||||
|
onSuccess
|
||||||
|
}: {
|
||||||
|
shipmentId: number;
|
||||||
|
onSuccess: (response: any) => void;
|
||||||
|
}) {
|
||||||
|
return useEditApiFormModal({
|
||||||
|
url: ApiEndpoints.sales_order_shipment_list,
|
||||||
|
pk: shipmentId,
|
||||||
|
title: t`Uncheck Shipment`,
|
||||||
|
preFormContent: (
|
||||||
|
<Alert color='red' icon={<IconCircleX />} title={t`Uncheck Shipment`}>
|
||||||
|
<Text>{t`Marking the shipment as unchecked indicates that the shipment requires further verification`}</Text>
|
||||||
|
</Alert>
|
||||||
|
),
|
||||||
|
fetchInitialData: false,
|
||||||
|
fields: {
|
||||||
|
checked_by: {
|
||||||
|
hidden: true,
|
||||||
|
value: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
successMessage: t`Shipment marked as unchecked`,
|
||||||
|
onFormSuccess: onSuccess
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function SalesOrderAllocateLineRow({
|
function SalesOrderAllocateLineRow({
|
||||||
props,
|
props,
|
||||||
record,
|
record,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { t } from '@lingui/core/macro';
|
import { t } from '@lingui/core/macro';
|
||||||
import { Alert, Grid, Skeleton, Stack, Text } from '@mantine/core';
|
import { Grid, Skeleton, Stack, Text } from '@mantine/core';
|
||||||
import {
|
import {
|
||||||
IconBookmark,
|
IconBookmark,
|
||||||
IconCircleCheck,
|
IconCircleCheck,
|
||||||
@@ -39,8 +39,10 @@ import { RenderAddress } from '../../components/render/Company';
|
|||||||
import { RenderUser } from '../../components/render/User';
|
import { RenderUser } from '../../components/render/User';
|
||||||
import { formatDate } from '../../defaults/formatters';
|
import { formatDate } from '../../defaults/formatters';
|
||||||
import {
|
import {
|
||||||
|
useCheckShipmentForm,
|
||||||
useSalesOrderShipmentCompleteFields,
|
useSalesOrderShipmentCompleteFields,
|
||||||
useSalesOrderShipmentFields
|
useSalesOrderShipmentFields,
|
||||||
|
useUncheckShipmentForm
|
||||||
} from '../../forms/SalesOrderForms';
|
} from '../../forms/SalesOrderForms';
|
||||||
import {
|
import {
|
||||||
useCreateApiFormModal,
|
useCreateApiFormModal,
|
||||||
@@ -320,44 +322,14 @@ export default function SalesOrderShipmentDetail() {
|
|||||||
onFormSuccess: refreshShipment
|
onFormSuccess: refreshShipment
|
||||||
});
|
});
|
||||||
|
|
||||||
const checkShipment = useEditApiFormModal({
|
const checkShipment = useCheckShipmentForm({
|
||||||
url: ApiEndpoints.sales_order_shipment_list,
|
shipmentId: shipment.pk,
|
||||||
pk: shipment.pk,
|
onSuccess: refreshShipment
|
||||||
title: t`Check Shipment`,
|
|
||||||
preFormContent: (
|
|
||||||
<Alert color='green' icon={<IconCircleCheck />} title={t`Check Shipment`}>
|
|
||||||
<Text>{t`Marking the shipment as checked indicates that you have verified that all items included in this shipment are correct`}</Text>
|
|
||||||
</Alert>
|
|
||||||
),
|
|
||||||
fetchInitialData: false,
|
|
||||||
fields: {
|
|
||||||
checked_by: {
|
|
||||||
hidden: true,
|
|
||||||
value: userId
|
|
||||||
}
|
|
||||||
},
|
|
||||||
successMessage: t`Shipment marked as checked`,
|
|
||||||
onFormSuccess: refreshShipment
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const uncheckShipment = useEditApiFormModal({
|
const uncheckShipment = useUncheckShipmentForm({
|
||||||
url: ApiEndpoints.sales_order_shipment_list,
|
shipmentId: shipment.pk,
|
||||||
pk: shipment.pk,
|
onSuccess: refreshShipment
|
||||||
title: t`Uncheck Shipment`,
|
|
||||||
preFormContent: (
|
|
||||||
<Alert color='red' icon={<IconCircleX />} title={t`Uncheck Shipment`}>
|
|
||||||
<Text>{t`Marking the shipment as unchecked indicates that the shipment requires further verification`}</Text>
|
|
||||||
</Alert>
|
|
||||||
),
|
|
||||||
fetchInitialData: false,
|
|
||||||
fields: {
|
|
||||||
checked_by: {
|
|
||||||
hidden: true,
|
|
||||||
value: null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
successMessage: t`Shipment marked as unchecked`,
|
|
||||||
onFormSuccess: refreshShipment
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const shipmentBadges = useMemo(() => {
|
const shipmentBadges = useMemo(() => {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { t } from '@lingui/core/macro';
|
import { t } from '@lingui/core/macro';
|
||||||
import { IconTruckDelivery } from '@tabler/icons-react';
|
import {
|
||||||
|
IconCircleCheck,
|
||||||
|
IconCircleX,
|
||||||
|
IconTruckDelivery
|
||||||
|
} from '@tabler/icons-react';
|
||||||
import { useCallback, useMemo, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
@@ -19,8 +23,10 @@ import type { TableFilter } from '@lib/types/Filters';
|
|||||||
import type { TableColumn } from '@lib/types/Tables';
|
import type { TableColumn } from '@lib/types/Tables';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import {
|
import {
|
||||||
|
useCheckShipmentForm,
|
||||||
useSalesOrderShipmentCompleteFields,
|
useSalesOrderShipmentCompleteFields,
|
||||||
useSalesOrderShipmentFields
|
useSalesOrderShipmentFields,
|
||||||
|
useUncheckShipmentForm
|
||||||
} from '../../forms/SalesOrderForms';
|
} from '../../forms/SalesOrderForms';
|
||||||
import {
|
import {
|
||||||
useCreateApiFormModal,
|
useCreateApiFormModal,
|
||||||
@@ -91,6 +97,20 @@ export default function SalesOrderShipmentTable({
|
|||||||
table: table
|
table: table
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const checkShipment = useCheckShipmentForm({
|
||||||
|
shipmentId: selectedShipment.pk,
|
||||||
|
onSuccess: () => {
|
||||||
|
table.refreshTable();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const uncheckShipment = useUncheckShipmentForm({
|
||||||
|
shipmentId: selectedShipment.pk,
|
||||||
|
onSuccess: () => {
|
||||||
|
table.refreshTable();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const completeShipment = useCreateApiFormModal({
|
const completeShipment = useCreateApiFormModal({
|
||||||
url: ApiEndpoints.sales_order_shipment_complete,
|
url: ApiEndpoints.sales_order_shipment_complete,
|
||||||
pk: selectedShipment.pk,
|
pk: selectedShipment.pk,
|
||||||
@@ -188,6 +208,30 @@ export default function SalesOrderShipmentTable({
|
|||||||
const shipped: boolean = !!record.shipment_date;
|
const shipped: boolean = !!record.shipment_date;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
{
|
||||||
|
hidden:
|
||||||
|
!!record.checked_by || !user.hasChangeRole(UserRoles.sales_order),
|
||||||
|
title: t`Check Shipment`,
|
||||||
|
color: 'blue',
|
||||||
|
icon: <IconCircleCheck />,
|
||||||
|
onClick: () => {
|
||||||
|
setSelectedShipment(record);
|
||||||
|
checkShipment.open();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hidden:
|
||||||
|
shipped ||
|
||||||
|
!record.checked_by ||
|
||||||
|
!user.hasChangeRole(UserRoles.sales_order),
|
||||||
|
title: t`Uncheck Shipment`,
|
||||||
|
color: 'red',
|
||||||
|
icon: <IconCircleX />,
|
||||||
|
onClick: () => {
|
||||||
|
setSelectedShipment(record);
|
||||||
|
uncheckShipment.open();
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
hidden: shipped || !user.hasChangeRole(UserRoles.sales_order),
|
hidden: shipped || !user.hasChangeRole(UserRoles.sales_order),
|
||||||
title: t`Complete Shipment`,
|
title: t`Complete Shipment`,
|
||||||
@@ -271,7 +315,9 @@ export default function SalesOrderShipmentTable({
|
|||||||
<>
|
<>
|
||||||
{newShipment.modal}
|
{newShipment.modal}
|
||||||
{editShipment.modal}
|
{editShipment.modal}
|
||||||
|
{checkShipment.modal}
|
||||||
{deleteShipment.modal}
|
{deleteShipment.modal}
|
||||||
|
{uncheckShipment.modal}
|
||||||
{completeShipment.modal}
|
{completeShipment.modal}
|
||||||
<InvenTreeTable
|
<InvenTreeTable
|
||||||
url={apiUrl(ApiEndpoints.sales_order_shipment_list)}
|
url={apiUrl(ApiEndpoints.sales_order_shipment_list)}
|
||||||
|
|||||||
Reference in New Issue
Block a user