mirror of
https://github.com/inventree/InvenTree.git
synced 2025-11-13 19:36:46 +00:00
[UI] Duplicate supplier part (#10809)
* Allow duplication of supplier part * Bug fix for pack quantity display * Allow duplication of ManufacturerPart
This commit is contained in:
@@ -5,6 +5,7 @@ import { AddItemButton } from '@lib/components/AddItemButton';
|
|||||||
import {
|
import {
|
||||||
type RowAction,
|
type RowAction,
|
||||||
RowDeleteAction,
|
RowDeleteAction,
|
||||||
|
RowDuplicateAction,
|
||||||
RowEditAction
|
RowEditAction
|
||||||
} from '@lib/components/RowActions';
|
} from '@lib/components/RowActions';
|
||||||
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
||||||
@@ -88,9 +89,7 @@ export function ManufacturerPartTable({
|
|||||||
|
|
||||||
const manufacturerPartFields = useManufacturerPartFields();
|
const manufacturerPartFields = useManufacturerPartFields();
|
||||||
|
|
||||||
const [selectedPart, setSelectedPart] = useState<number | undefined>(
|
const [selectedPart, setSelectedPart] = useState<any>(undefined);
|
||||||
undefined
|
|
||||||
);
|
|
||||||
|
|
||||||
const createManufacturerPart = useCreateApiFormModal({
|
const createManufacturerPart = useCreateApiFormModal({
|
||||||
url: ApiEndpoints.manufacturer_part_list,
|
url: ApiEndpoints.manufacturer_part_list,
|
||||||
@@ -105,15 +104,25 @@ export function ManufacturerPartTable({
|
|||||||
|
|
||||||
const editManufacturerPart = useEditApiFormModal({
|
const editManufacturerPart = useEditApiFormModal({
|
||||||
url: ApiEndpoints.manufacturer_part_list,
|
url: ApiEndpoints.manufacturer_part_list,
|
||||||
pk: selectedPart,
|
pk: selectedPart?.pk,
|
||||||
title: t`Edit Manufacturer Part`,
|
title: t`Edit Manufacturer Part`,
|
||||||
fields: manufacturerPartFields,
|
fields: useMemo(() => manufacturerPartFields, [manufacturerPartFields]),
|
||||||
table: table
|
table: table
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const duplicateManufacturerPart = useCreateApiFormModal({
|
||||||
|
url: ApiEndpoints.manufacturer_part_list,
|
||||||
|
title: t`Add Manufacturer Part`,
|
||||||
|
fields: useMemo(() => manufacturerPartFields, [manufacturerPartFields]),
|
||||||
|
table: table,
|
||||||
|
initialData: {
|
||||||
|
...selectedPart
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const deleteManufacturerPart = useDeleteApiFormModal({
|
const deleteManufacturerPart = useDeleteApiFormModal({
|
||||||
url: ApiEndpoints.manufacturer_part_list,
|
url: ApiEndpoints.manufacturer_part_list,
|
||||||
pk: selectedPart,
|
pk: selectedPart?.pk,
|
||||||
title: t`Delete Manufacturer Part`,
|
title: t`Delete Manufacturer Part`,
|
||||||
table: table
|
table: table
|
||||||
});
|
});
|
||||||
@@ -157,14 +166,21 @@ export function ManufacturerPartTable({
|
|||||||
RowEditAction({
|
RowEditAction({
|
||||||
hidden: !user.hasChangeRole(UserRoles.purchase_order),
|
hidden: !user.hasChangeRole(UserRoles.purchase_order),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setSelectedPart(record.pk);
|
setSelectedPart(record);
|
||||||
editManufacturerPart.open();
|
editManufacturerPart.open();
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
RowDuplicateAction({
|
||||||
|
hidden: !user.hasAddRole(UserRoles.purchase_order),
|
||||||
|
onClick: () => {
|
||||||
|
setSelectedPart(record);
|
||||||
|
duplicateManufacturerPart.open();
|
||||||
|
}
|
||||||
|
}),
|
||||||
RowDeleteAction({
|
RowDeleteAction({
|
||||||
hidden: !user.hasDeleteRole(UserRoles.purchase_order),
|
hidden: !user.hasDeleteRole(UserRoles.purchase_order),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setSelectedPart(record.pk);
|
setSelectedPart(record);
|
||||||
deleteManufacturerPart.open();
|
deleteManufacturerPart.open();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -176,6 +192,7 @@ export function ManufacturerPartTable({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{createManufacturerPart.modal}
|
{createManufacturerPart.modal}
|
||||||
|
{duplicateManufacturerPart.modal}
|
||||||
{editManufacturerPart.modal}
|
{editManufacturerPart.modal}
|
||||||
{deleteManufacturerPart.modal}
|
{deleteManufacturerPart.modal}
|
||||||
<InvenTreeTable
|
<InvenTreeTable
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ import { AddItemButton } from '@lib/components/AddItemButton';
|
|||||||
import {
|
import {
|
||||||
type RowAction,
|
type RowAction,
|
||||||
RowDeleteAction,
|
RowDeleteAction,
|
||||||
|
RowDuplicateAction,
|
||||||
RowEditAction
|
RowEditAction
|
||||||
} from '@lib/components/RowActions';
|
} from '@lib/components/RowActions';
|
||||||
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
||||||
import { ModelType } from '@lib/enums/ModelType';
|
import { ModelType } from '@lib/enums/ModelType';
|
||||||
import { UserRoles } from '@lib/enums/Roles';
|
import { UserRoles } from '@lib/enums/Roles';
|
||||||
import { apiUrl } from '@lib/functions/Api';
|
import { apiUrl } from '@lib/functions/Api';
|
||||||
import { formatDecimal } from '@lib/functions/Formatting';
|
|
||||||
import type { TableFilter } from '@lib/types/Filters';
|
import type { TableFilter } from '@lib/types/Filters';
|
||||||
import type { TableColumn } from '@lib/types/Tables';
|
import type { TableColumn } from '@lib/types/Tables';
|
||||||
import { IconPackageImport } from '@tabler/icons-react';
|
import { IconPackageImport } from '@tabler/icons-react';
|
||||||
@@ -118,7 +118,6 @@ export function SupplierPartTable({
|
|||||||
{
|
{
|
||||||
accessor: 'pack_quantity',
|
accessor: 'pack_quantity',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
|
|
||||||
render: (record: any) => {
|
render: (record: any) => {
|
||||||
const part = record?.part_detail ?? {};
|
const part = record?.part_detail ?? {};
|
||||||
|
|
||||||
@@ -126,7 +125,7 @@ export function SupplierPartTable({
|
|||||||
|
|
||||||
if (part.units) {
|
if (part.units) {
|
||||||
extra.push(
|
extra.push(
|
||||||
<Text key='base'>
|
<Text key='base' size='sm'>
|
||||||
{t`Base units`} : {part.units}
|
{t`Base units`} : {part.units}
|
||||||
</Text>
|
</Text>
|
||||||
);
|
);
|
||||||
@@ -134,7 +133,7 @@ export function SupplierPartTable({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<TableHoverCard
|
<TableHoverCard
|
||||||
value={formatDecimal(record.pack_quantity)}
|
value={record.pack_quantity}
|
||||||
extra={extra}
|
extra={extra}
|
||||||
title={t`Pack Quantity`}
|
title={t`Pack Quantity`}
|
||||||
/>
|
/>
|
||||||
@@ -236,19 +235,32 @@ export function SupplierPartTable({
|
|||||||
|
|
||||||
const editSupplierPartFields = useSupplierPartFields({});
|
const editSupplierPartFields = useSupplierPartFields({});
|
||||||
|
|
||||||
const [selectedSupplierPart, setSelectedSupplierPart] = useState<number>(0);
|
const [selectedSupplierPart, setSelectedSupplierPart] =
|
||||||
|
useState<any>(undefined);
|
||||||
|
|
||||||
const editSupplierPart = useEditApiFormModal({
|
const editSupplierPart = useEditApiFormModal({
|
||||||
url: ApiEndpoints.supplier_part_list,
|
url: ApiEndpoints.supplier_part_list,
|
||||||
pk: selectedSupplierPart,
|
pk: selectedSupplierPart?.pk,
|
||||||
title: t`Edit Supplier Part`,
|
title: t`Edit Supplier Part`,
|
||||||
fields: editSupplierPartFields,
|
fields: useMemo(() => editSupplierPartFields, [editSupplierPartFields]),
|
||||||
table: table
|
table: table
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const duplicateSupplierPart = useCreateApiFormModal({
|
||||||
|
url: ApiEndpoints.supplier_part_list,
|
||||||
|
title: t`Add Supplier Part`,
|
||||||
|
fields: useMemo(() => editSupplierPartFields, [editSupplierPartFields]),
|
||||||
|
initialData: {
|
||||||
|
...selectedSupplierPart,
|
||||||
|
active: true
|
||||||
|
},
|
||||||
|
table: table,
|
||||||
|
successMessage: t`Supplier part created`
|
||||||
|
});
|
||||||
|
|
||||||
const deleteSupplierPart = useDeleteApiFormModal({
|
const deleteSupplierPart = useDeleteApiFormModal({
|
||||||
url: ApiEndpoints.supplier_part_list,
|
url: ApiEndpoints.supplier_part_list,
|
||||||
pk: selectedSupplierPart,
|
pk: selectedSupplierPart?.pk,
|
||||||
title: t`Delete Supplier Part`,
|
title: t`Delete Supplier Part`,
|
||||||
table: table
|
table: table
|
||||||
});
|
});
|
||||||
@@ -260,14 +272,21 @@ export function SupplierPartTable({
|
|||||||
RowEditAction({
|
RowEditAction({
|
||||||
hidden: !user.hasChangeRole(UserRoles.purchase_order),
|
hidden: !user.hasChangeRole(UserRoles.purchase_order),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setSelectedSupplierPart(record.pk);
|
setSelectedSupplierPart(record);
|
||||||
editSupplierPart.open();
|
editSupplierPart.open();
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
RowDuplicateAction({
|
||||||
|
hidden: !user.hasAddRole(UserRoles.purchase_order),
|
||||||
|
onClick: () => {
|
||||||
|
setSelectedSupplierPart(record);
|
||||||
|
duplicateSupplierPart.open();
|
||||||
|
}
|
||||||
|
}),
|
||||||
RowDeleteAction({
|
RowDeleteAction({
|
||||||
hidden: !user.hasDeleteRole(UserRoles.purchase_order),
|
hidden: !user.hasDeleteRole(UserRoles.purchase_order),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setSelectedSupplierPart(record.pk);
|
setSelectedSupplierPart(record);
|
||||||
deleteSupplierPart.open();
|
deleteSupplierPart.open();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -280,6 +299,7 @@ export function SupplierPartTable({
|
|||||||
<>
|
<>
|
||||||
{addSupplierPart.modal}
|
{addSupplierPart.modal}
|
||||||
{editSupplierPart.modal}
|
{editSupplierPart.modal}
|
||||||
|
{duplicateSupplierPart.modal}
|
||||||
{deleteSupplierPart.modal}
|
{deleteSupplierPart.modal}
|
||||||
{importPartWizard.wizard}
|
{importPartWizard.wizard}
|
||||||
<InvenTreeTable
|
<InvenTreeTable
|
||||||
|
|||||||
Reference in New Issue
Block a user