From 4307e6d17096d448757983cbc12eaed645dcabc3 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 3 Jul 2025 16:53:46 +1000 Subject: [PATCH] Allocation search by IPN (#9944) * Fix for "has_ipn" filter * Enable filtering and sorting by IPN in SalesOrderAllocation table * Bump API version --- src/backend/InvenTree/InvenTree/api_version.py | 6 +++++- src/backend/InvenTree/order/api.py | 9 ++++++++- src/backend/InvenTree/part/api.py | 4 ++-- .../src/tables/sales/SalesOrderAllocationTable.tsx | 3 ++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index ef3a80ae9b..2bb8e60673 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -1,12 +1,16 @@ """InvenTree API version information.""" # InvenTree API version -INVENTREE_API_VERSION = 360 +INVENTREE_API_VERSION = 361 """Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" INVENTREE_API_TEXT = """ +v361 -> 2025-07-03 : https://github.com/inventree/InvenTree/pull/9944 + - Enable SalesOrderAllocation list to be filtered by part IPN value + - Enable SalesOrderAllocation list to be ordered by part MPN value + v360 -> 2025-07-02 : https://github.com/inventree/InvenTree/pull/9937 - Provide more detailed StockItem information in the BuildItem serializer - Provide more detailed StockItem information in the SalesOrderAllocation serializer diff --git a/src/backend/InvenTree/order/api.py b/src/backend/InvenTree/order/api.py index dfeda69ebf..04279c4e98 100644 --- a/src/backend/InvenTree/order/api.py +++ b/src/backend/InvenTree/order/api.py @@ -1217,6 +1217,7 @@ class SalesOrderAllocationList(SalesOrderAllocationMixin, BulkUpdateMixin, ListA 'quantity', 'part', 'serial', + 'IPN', 'batch', 'location', 'order', @@ -1224,6 +1225,7 @@ class SalesOrderAllocationList(SalesOrderAllocationMixin, BulkUpdateMixin, ListA ] ordering_field_aliases = { + 'IPN': 'item__part__IPN', 'part': 'item__part__name', 'serial': ['item__serial_int', 'item__serial'], 'batch': 'item__batch', @@ -1232,7 +1234,12 @@ class SalesOrderAllocationList(SalesOrderAllocationMixin, BulkUpdateMixin, ListA 'shipment_date': 'shipment__shipment_date', } - search_fields = {'item__part__name', 'item__serial', 'item__batch'} + search_fields = { + 'item__part__name', + 'item__part__IPN', + 'item__serial', + 'item__batch', + } def get_serializer(self, *args, **kwargs): """Return the serializer instance for this endpoint. diff --git a/src/backend/InvenTree/part/api.py b/src/backend/InvenTree/part/api.py index 53a4b5c167..e9c41248f8 100644 --- a/src/backend/InvenTree/part/api.py +++ b/src/backend/InvenTree/part/api.py @@ -716,8 +716,8 @@ class PartFilter(rest_filters.FilterSet): def filter_has_ipn(self, queryset, name, value): """Filter by whether the Part has an IPN (internal part number) or not.""" if str2bool(value): - return queryset.exclude(IPN='') - return queryset.filter(IPN='') + return queryset.exclude(IPN='').exclude(IPN=None) + return queryset.filter(Q(IPN='') | Q(IPN=None)).distinct() # Regex filter for name name_regex = rest_filters.CharFilter( diff --git a/src/frontend/src/tables/sales/SalesOrderAllocationTable.tsx b/src/frontend/src/tables/sales/SalesOrderAllocationTable.tsx index ab53189bb0..92f477f82b 100644 --- a/src/frontend/src/tables/sales/SalesOrderAllocationTable.tsx +++ b/src/frontend/src/tables/sales/SalesOrderAllocationTable.tsx @@ -134,7 +134,8 @@ export default function SalesOrderAllocationTable({ accessor: 'part_detail.IPN', title: t`IPN`, hidden: showPartInfo != true, - sortable: false + sortable: true, + ordering: 'IPN' }, { accessor: 'serial',