[PUI] Update part duplicate forms (#7575)

- Enable copying of part details when duplicating a part
- Update forms
This commit is contained in:
Oliver 2024-07-07 12:50:31 +10:00 committed by GitHub
parent 8309eb628f
commit 3ce0202ffd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 3 deletions

View File

@ -603,6 +603,8 @@ class PartSerializer(
Used when displaying all details of a single component.
"""
import_exclude_fields = ['duplicate']
class Meta:
"""Metaclass defining serializer fields."""

View File

@ -57,7 +57,9 @@ export function usePartFields({
fields.initial_stock = {
icon: <IconPackages />,
children: {
quantity: {},
quantity: {
value: 0
},
location: {}
}
};

View File

@ -34,6 +34,7 @@ import { DetailsImage } from '../../components/details/DetailsImage';
import { ItemDetailsGrid } from '../../components/details/ItemDetails';
import { PartIcons } from '../../components/details/PartIcons';
import NotesEditor from '../../components/editors/NotesEditor';
import { ApiFormFieldSet } from '../../components/forms/fields/ApiFormField';
import { Thumbnail } from '../../components/images/Thumbnail';
import {
ActionDropdown,
@ -718,12 +719,34 @@ export default function PartDetail() {
onFormSuccess: refreshInstance
});
const createPartFields = usePartFields({ create: true });
const duplicatePartFields: ApiFormFieldSet = useMemo(() => {
return {
...createPartFields,
duplicate: {
children: {
part: {
value: part.pk,
hidden: true
},
copy_image: {},
copy_bom: {},
copy_notes: {},
copy_parameters: {}
}
}
};
}, [createPartFields, part]);
const duplicatePart = useCreateApiFormModal({
url: ApiEndpoints.part_list,
title: t`Add Part`,
fields: partFields,
fields: duplicatePartFields,
initialData: {
...part
...part,
active: true,
locked: false
},
follow: true,
modelType: ModelType.part