From 4b1ddcd2d0478ecf8d7fd4bb573cfb7a81ab6ec1 Mon Sep 17 00:00:00 2001 From: Bhumin Paladiya <139330832+bhumin18@users.noreply.github.com> Date: Thu, 3 Sep 2026 04:19:53 +0530 Subject: [PATCH] Enhance search fields across InvenTree REST API endpoints (#12723) * Enhance search fields across REST API endpoints * Revert search_fields on SettingsList to key only for security * Bump API version to 537 for REST API search fields * Clean TokenListView search fields and revert common/api.py --- .../InvenTree/InvenTree/api_version.py | 5 ++++- src/backend/InvenTree/company/api.py | 19 +++++++++++++++++-- src/backend/InvenTree/order/api.py | 11 +++++++---- src/backend/InvenTree/users/api.py | 16 +++++++--------- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index 264f2dfc52..801922c937 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -1,11 +1,14 @@ """InvenTree API version information.""" # InvenTree API version -INVENTREE_API_VERSION = 538 +INVENTREE_API_VERSION = 539 """Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" INVENTREE_API_TEXT = """ +v539 -> 2026-09-02 : https://github.com/inventree/InvenTree/pull/12723 + - Adds search fields to AddressList, ContactList, UserList, GroupList, RuleSetList, and TokenListView API endpoints + v538 -> 2026-09-02 : https://github.com/inventree/InvenTree/pull/12763 - Fix API permissions for the SelectionList endpoints diff --git a/src/backend/InvenTree/company/api.py b/src/backend/InvenTree/company/api.py index 58642a30fa..6465a270c0 100644 --- a/src/backend/InvenTree/company/api.py +++ b/src/backend/InvenTree/company/api.py @@ -98,7 +98,7 @@ class ContactList(DataExportViewMixin, ListCreateDestroyAPIView): filterset_fields = ['company'] - search_fields = ['company__name', 'name'] + search_fields = ['company__name', 'name', 'email', 'phone', 'role'] ordering_fields = ['name'] @@ -122,6 +122,16 @@ class AddressList(DataExportViewMixin, ListCreateDestroyAPIView): filterset_fields = ['company'] + search_fields = [ + 'company__name', + 'title', + 'line1', + 'line2', + 'postal_city', + 'postal_code', + 'country', + ] + ordering_fields = ['title'] ordering = 'title' @@ -491,7 +501,12 @@ class SupplierPriceBreakList( filter_backends = SEARCH_ORDER_FILTER ordering_fields = ['quantity', 'supplier', 'SKU', 'price'] - search_fields = ['part__SKU', 'part__supplier__name'] + search_fields = [ + 'part__SKU', + 'part__supplier__name', + 'part__part__name', + 'part__part__IPN', + ] ordering_field_aliases = {'supplier': 'part__supplier__name', 'SKU': 'part__SKU'} diff --git a/src/backend/InvenTree/order/api.py b/src/backend/InvenTree/order/api.py index 34c4d73f59..b193665206 100644 --- a/src/backend/InvenTree/order/api.py +++ b/src/backend/InvenTree/order/api.py @@ -1479,12 +1479,14 @@ class SalesOrderAllocationList( 'shipment_date': 'shipment__shipment_date', } - search_fields = { + search_fields = [ 'item__part__name', 'item__part__IPN', 'item__serial', 'item__batch', - } + 'line__order__reference', + 'line__order__customer__name', + ] class SalesOrderAllocationDetail(SalesOrderAllocationMixin, RetrieveUpdateDestroyAPI): @@ -2295,12 +2297,13 @@ class TransferOrderAllocationList( 'order': 'line__order__reference', } - search_fields = { + search_fields = [ 'item__part__name', 'item__part__IPN', 'item__serial', 'item__batch', - } + 'line__order__reference', + ] class TransferOrderAllocationDetail( diff --git a/src/backend/InvenTree/users/api.py b/src/backend/InvenTree/users/api.py index 74df95bfe9..48cba59796 100644 --- a/src/backend/InvenTree/users/api.py +++ b/src/backend/InvenTree/users/api.py @@ -283,7 +283,7 @@ class UserList(ListCreateAPI): filter_backends = SEARCH_ORDER_FILTER - search_fields = ['first_name', 'last_name', 'username'] + search_fields = ['first_name', 'last_name', 'username', 'email'] ordering_fields = [ 'email', @@ -459,16 +459,14 @@ class TokenListView(TokenMixin, ListCreateAPI): """List of user tokens for current user.""" filter_backends = SEARCH_ORDER_FILTER - search_fields = ['name', 'key'] - ordering_fields = [ - 'created', - 'expiry', - 'last_seen', - 'user', + search_fields = [ 'name', - 'revoked', - 'revoked', + 'user__username', + 'user__first_name', + 'user__last_name', + 'user__email', ] + ordering_fields = ['created', 'expiry', 'last_seen', 'user', 'name', 'revoked'] filterset_fields = ['revoked', 'user'] queryset = ApiToken.objects.none()