From 18b7baa5b9834d0881d43fc96c7dee459a9a85c0 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 18 May 2020 13:32:50 +1000 Subject: [PATCH] Allow stock item filtering by IPN (cherry picked from commit bd9aad935594e4022299567667faeb149f6d2375) --- InvenTree/stock/api.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index aad36cc3dc..93cf9067f3 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -499,7 +499,7 @@ class StockList(generics.ListCreateAPIView): if serial_number is not None: queryset = queryset.filter(serial=serial_number) - in_stock = self.request.query_params.get('in_stock', None) + in_stock = params.get('in_stock', None) if in_stock is not None: in_stock = str2bool(in_stock) @@ -512,7 +512,7 @@ class StockList(generics.ListCreateAPIView): queryset = queryset.exclude(StockItem.IN_STOCK_FILTER) # Filter by 'allocated' patrs? - allocated = self.request.query_params.get('allocated', None) + allocated = params.get('allocated', None) if allocated is not None: allocated = str2bool(allocated) @@ -531,8 +531,14 @@ class StockList(generics.ListCreateAPIView): active = str2bool(active) queryset = queryset.filter(part__active=active) + # Filter by internal part number + IPN = params.get('IPN', None) + + if IPN: + queryset = queryset.filter(part__IPN=IPN) + # Does the client wish to filter by the Part ID? - part_id = self.request.query_params.get('part', None) + part_id = params.get('part', None) if part_id: try: