From 402301e165e7a4a5911994547513383609cdc503 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 17:06:22 +1000 Subject: [PATCH] Add ability to filter stock items by "depleted" status --- InvenTree/stock/api.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 018b588c1f..023b0c6c4e 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -539,10 +539,21 @@ class StockList(generics.ListCreateAPIView): active = str2bool(active) queryset = queryset.filter(part__active=active) + # Filter by 'depleted' status + depleted = params.get('depleted', None) + + if depleted is not None: + depleted = str2bool(depleted) + + if depleted: + queryset = queryset.filter(quantity__lte=0) + else: + queryset = queryset.exclude(quantity__lte=0) + # Filter by internal part number IPN = params.get('IPN', None) - if IPN: + if IPN is not None: queryset = queryset.filter(part__IPN=IPN) # Does the client wish to filter by the Part ID?