diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index 40bff36d69..181abf41c9 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -1,12 +1,15 @@ """InvenTree API version information.""" # 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.""" 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 - Adds custom status fields to various serializers diff --git a/src/backend/InvenTree/stock/serializers.py b/src/backend/InvenTree/stock/serializers.py index 58ed3a2471..7c80285f6f 100644 --- a/src/backend/InvenTree/stock/serializers.py +++ b/src/backend/InvenTree/stock/serializers.py @@ -239,7 +239,10 @@ class StockItemTestResultSerializer( ) attachment = InvenTree.serializers.InvenTreeAttachmentSerializerField( - required=False + required=False, + allow_null=True, + label=_('Attachment'), + help_text=_('Test result attachment'), ) def validate(self, data): diff --git a/src/frontend/src/forms/StockForms.tsx b/src/frontend/src/forms/StockForms.tsx index 0577233192..7ac947826b 100644 --- a/src/frontend/src/forms/StockForms.tsx +++ b/src/frontend/src/forms/StockForms.tsx @@ -922,10 +922,14 @@ export function stockLocationFields(): ApiFormFieldSet { // Construct a set of fields for export function useTestResultFields({ partId, - itemId + itemId, + templateId, + editTemplate = false }: { partId: number; itemId: number; + templateId: number | undefined; + editTemplate?: boolean; }): ApiFormFieldSet { // Valid field choices const [choices, setChoices] = useState([]); @@ -947,6 +951,7 @@ export function useTestResultFields({ hidden: true }, template: { + disabled: !editTemplate && !!templateId, filters: { include_inherited: true, part: partId @@ -990,5 +995,13 @@ export function useTestResultFields({ hidden: !includeTestStation } }; - }, [choices, fieldType, partId, itemId, includeTestStation]); + }, [ + choices, + editTemplate, + fieldType, + partId, + itemId, + templateId, + includeTestStation + ]); } diff --git a/src/frontend/src/tables/build/BuildOrderTestTable.tsx b/src/frontend/src/tables/build/BuildOrderTestTable.tsx index dc4145ae5c..4905945e9d 100644 --- a/src/frontend/src/tables/build/BuildOrderTestTable.tsx +++ b/src/frontend/src/tables/build/BuildOrderTestTable.tsx @@ -67,7 +67,8 @@ export default function BuildOrderTestTable({ const testResultFields: ApiFormFieldSet = useTestResultFields({ partId: partId, - itemId: selectedOutput + itemId: selectedOutput, + templateId: selectedTemplate }); const createTestResult = useCreateApiFormModal({ diff --git a/src/frontend/src/tables/stock/StockItemTestResultTable.tsx b/src/frontend/src/tables/stock/StockItemTestResultTable.tsx index fe41d0ac12..4eca85588f 100644 --- a/src/frontend/src/tables/stock/StockItemTestResultTable.tsx +++ b/src/frontend/src/tables/stock/StockItemTestResultTable.tsx @@ -238,15 +238,16 @@ export default function StockItemTestResultTable({ ]; }, [itemId]); - const resultFields: ApiFormFieldSet = useTestResultFields({ - partId: partId, - itemId: itemId - }); - const [selectedTemplate, setSelectedTemplate] = useState( undefined ); + const resultFields: ApiFormFieldSet = useTestResultFields({ + partId: partId, + itemId: itemId, + templateId: selectedTemplate + }); + const newTestModal = useCreateApiFormModal({ url: ApiEndpoints.stock_test_result_list, fields: useMemo(() => ({ ...resultFields }), [resultFields]),