From 750e6d81fa5b663b5deadcf17d362effd87e699c Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 14 Jul 2024 20:49:46 +1000 Subject: [PATCH] Allocated stock table fix (#7636) * Expose batch code field to StockItemSerializerBrief * Expose more fields to PartBriefSerializer * Additional export fields to BuildItemSerializer * Bump API version * Fix playwright test --- src/backend/InvenTree/InvenTree/api_version.py | 7 ++++++- src/backend/InvenTree/build/serializers.py | 7 +++++++ src/backend/InvenTree/part/serializers.py | 2 ++ src/backend/InvenTree/stock/serializers.py | 1 + src/frontend/src/pages/stock/StockDetail.tsx | 1 - .../src/tables/build/BuildAllocatedStockTable.tsx | 12 +++++++++++- src/frontend/tests/pages/pui_build.spec.ts | 4 ++-- 7 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index b11316cb69..3a2894e99d 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -1,12 +1,17 @@ """InvenTree API version information.""" # InvenTree API version -INVENTREE_API_VERSION = 220 +INVENTREE_API_VERSION = 221 """Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" INVENTREE_API_TEXT = """ +v221 - 2024-07-13 : https://github.com/inventree/InvenTree/pull/7636 + - Adds missing fields from StockItemBriefSerializer + - Adds missing fields from PartBriefSerializer + - Adds extra exportable fields to BuildItemSerializer + v220 - 2024-07-11 : https://github.com/inventree/InvenTree/pull/7585 - Adds "revision_of" field to Part serializer - Adds new API filters for "revision" status diff --git a/src/backend/InvenTree/build/serializers.py b/src/backend/InvenTree/build/serializers.py index 7c8bb2a0aa..390cabab92 100644 --- a/src/backend/InvenTree/build/serializers.py +++ b/src/backend/InvenTree/build/serializers.py @@ -1072,6 +1072,8 @@ class BuildItemSerializer(DataImportExportSerializerMixin, InvenTreeModelSeriali 'part_name', 'part_ipn', 'available_quantity', + 'item_batch_code', + 'item_serial', ] class Meta: @@ -1103,6 +1105,8 @@ class BuildItemSerializer(DataImportExportSerializerMixin, InvenTreeModelSeriali 'part_name', 'part_ipn', 'available_quantity', + 'item_batch_code', + 'item_serial_number', ] def __init__(self, *args, **kwargs): @@ -1138,6 +1142,9 @@ class BuildItemSerializer(DataImportExportSerializerMixin, InvenTreeModelSeriali part_name = serializers.CharField(source='stock_item.part.name', label=_('Part Name'), read_only=True) part_ipn = serializers.CharField(source='stock_item.part.IPN', label=_('Part IPN'), read_only=True) + item_batch_code = serializers.CharField(source='stock_item.batch', label=_('Batch Code'), read_only=True) + item_serial_number = serializers.CharField(source='stock_item.serial', label=_('Serial Number'), read_only=True) + # Annotated fields build = serializers.PrimaryKeyRelatedField(source='build_line.build', many=False, read_only=True) diff --git a/src/backend/InvenTree/part/serializers.py b/src/backend/InvenTree/part/serializers.py index a5e4f783d6..b05a426ed1 100644 --- a/src/backend/InvenTree/part/serializers.py +++ b/src/backend/InvenTree/part/serializers.py @@ -309,7 +309,9 @@ class PartBriefSerializer(InvenTree.serializers.InvenTreeModelSerializer): 'image', 'thumbnail', 'active', + 'locked', 'assembly', + 'component', 'is_template', 'purchaseable', 'salable', diff --git a/src/backend/InvenTree/stock/serializers.py b/src/backend/InvenTree/stock/serializers.py index fa9e060e72..8cbdd28566 100644 --- a/src/backend/InvenTree/stock/serializers.py +++ b/src/backend/InvenTree/stock/serializers.py @@ -306,6 +306,7 @@ class StockItemSerializerBrief( 'location', 'quantity', 'serial', + 'batch', 'supplier_part', 'barcode_hash', ] diff --git a/src/frontend/src/pages/stock/StockDetail.tsx b/src/frontend/src/pages/stock/StockDetail.tsx index c07814af48..63abe0d829 100644 --- a/src/frontend/src/pages/stock/StockDetail.tsx +++ b/src/frontend/src/pages/stock/StockDetail.tsx @@ -57,7 +57,6 @@ import { useEditApiFormModal } from '../../hooks/UseForm'; import { useInstance } from '../../hooks/UseInstance'; -import { apiUrl } from '../../states/ApiState'; import { useUserState } from '../../states/UserState'; import { AttachmentTable } from '../../tables/general/AttachmentTable'; import InstalledItemsTable from '../../tables/stock/InstalledItemsTable'; diff --git a/src/frontend/src/tables/build/BuildAllocatedStockTable.tsx b/src/frontend/src/tables/build/BuildAllocatedStockTable.tsx index 56d68d6404..f89939fe92 100644 --- a/src/frontend/src/tables/build/BuildAllocatedStockTable.tsx +++ b/src/frontend/src/tables/build/BuildAllocatedStockTable.tsx @@ -2,6 +2,7 @@ import { t } from '@lingui/macro'; import { useCallback, useMemo, useState } from 'react'; import { ApiEndpoints } from '../../enums/ApiEndpoints'; +import { ModelType } from '../../enums/ModelType'; import { UserRoles } from '../../enums/Roles'; import { useDeleteApiFormModal, @@ -58,6 +59,13 @@ export default function BuildAllocatedStockTable({ sortable: true, switchable: false }, + { + accessor: 'serial', + title: t`Serial Number`, + sortable: false, + switchable: true, + render: (record: any) => record?.stock_item_detail?.serial + }, { accessor: 'batch', title: t`Batch Code`, @@ -150,7 +158,9 @@ export default function BuildAllocatedStockTable({ enableDownload: true, enableSelection: true, rowActions: rowActions, - tableFilters: tableFilters + tableFilters: tableFilters, + modelField: 'stock_item', + modelType: ModelType.stockitem }} /> diff --git a/src/frontend/tests/pages/pui_build.spec.ts b/src/frontend/tests/pages/pui_build.spec.ts index 0703380ee1..93df2ca397 100644 --- a/src/frontend/tests/pages/pui_build.spec.ts +++ b/src/frontend/tests/pages/pui_build.spec.ts @@ -19,10 +19,10 @@ test('PUI - Pages - Build Order', async ({ page }) => { await page.getByRole('tab', { name: 'Allocated Stock' }).click(); // Check for expected text in the table - await page.getByText('R_10R_0402_1%').click(); + await page.getByText('R_10R_0402_1%').waitFor(); await page .getByRole('cell', { name: 'R38, R39, R40, R41, R42, R43' }) - .click(); + .waitFor(); // Click through to the "parent" build await page.getByRole('tab', { name: 'Build Details' }).click();