[PUI] Test result fixes (#7956)

* Prevent template adjustment

* Prevent template from being edited

* Fix 'attachment' field for StockItemTestResultSerializer

- Allow 'null' value

* Bump API version
This commit is contained in:
Oliver 2024-08-22 13:50:04 +10:00 committed by GitHub
parent b0c7a1aed5
commit ca87df3c3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 10 deletions

View File

@ -1,12 +1,15 @@
"""InvenTree API version information.""" """InvenTree API version information."""
# InvenTree API version # InvenTree API version
INVENTREE_API_VERSION = 246 INVENTREE_API_VERSION = 247
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" """Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """ INVENTREE_API_TEXT = """
v247 - 2024-08-22 : https://github.com/inventree/InvenTree/pull/7956
- Adjust "attachment" field on StockItemTestResult serializer
- Allow null values for attachment
v246 - 2024-08-21 : https://github.com/inventree/InvenTree/pull/7862 v246 - 2024-08-21 : https://github.com/inventree/InvenTree/pull/7862
- Adds custom status fields to various serializers - Adds custom status fields to various serializers

View File

@ -239,7 +239,10 @@ class StockItemTestResultSerializer(
) )
attachment = InvenTree.serializers.InvenTreeAttachmentSerializerField( attachment = InvenTree.serializers.InvenTreeAttachmentSerializerField(
required=False required=False,
allow_null=True,
label=_('Attachment'),
help_text=_('Test result attachment'),
) )
def validate(self, data): def validate(self, data):

View File

@ -922,10 +922,14 @@ export function stockLocationFields(): ApiFormFieldSet {
// Construct a set of fields for // Construct a set of fields for
export function useTestResultFields({ export function useTestResultFields({
partId, partId,
itemId itemId,
templateId,
editTemplate = false
}: { }: {
partId: number; partId: number;
itemId: number; itemId: number;
templateId: number | undefined;
editTemplate?: boolean;
}): ApiFormFieldSet { }): ApiFormFieldSet {
// Valid field choices // Valid field choices
const [choices, setChoices] = useState<any[]>([]); const [choices, setChoices] = useState<any[]>([]);
@ -947,6 +951,7 @@ export function useTestResultFields({
hidden: true hidden: true
}, },
template: { template: {
disabled: !editTemplate && !!templateId,
filters: { filters: {
include_inherited: true, include_inherited: true,
part: partId part: partId
@ -990,5 +995,13 @@ export function useTestResultFields({
hidden: !includeTestStation hidden: !includeTestStation
} }
}; };
}, [choices, fieldType, partId, itemId, includeTestStation]); }, [
choices,
editTemplate,
fieldType,
partId,
itemId,
templateId,
includeTestStation
]);
} }

View File

@ -67,7 +67,8 @@ export default function BuildOrderTestTable({
const testResultFields: ApiFormFieldSet = useTestResultFields({ const testResultFields: ApiFormFieldSet = useTestResultFields({
partId: partId, partId: partId,
itemId: selectedOutput itemId: selectedOutput,
templateId: selectedTemplate
}); });
const createTestResult = useCreateApiFormModal({ const createTestResult = useCreateApiFormModal({

View File

@ -238,15 +238,16 @@ export default function StockItemTestResultTable({
]; ];
}, [itemId]); }, [itemId]);
const resultFields: ApiFormFieldSet = useTestResultFields({
partId: partId,
itemId: itemId
});
const [selectedTemplate, setSelectedTemplate] = useState<number | undefined>( const [selectedTemplate, setSelectedTemplate] = useState<number | undefined>(
undefined undefined
); );
const resultFields: ApiFormFieldSet = useTestResultFields({
partId: partId,
itemId: itemId,
templateId: selectedTemplate
});
const newTestModal = useCreateApiFormModal({ const newTestModal = useCreateApiFormModal({
url: ApiEndpoints.stock_test_result_list, url: ApiEndpoints.stock_test_result_list,
fields: useMemo(() => ({ ...resultFields }), [resultFields]), fields: useMemo(() => ({ ...resultFields }), [resultFields]),