Merge pull request #814 from SchrodingersGat/api-tweaks

Allow stock item filtering by IPN
This commit is contained in:
Oliver 2020-05-18 13:38:23 +10:00 committed by GitHub
commit 05e4c8f825
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -499,7 +499,7 @@ class StockList(generics.ListCreateAPIView):
if serial_number is not None: if serial_number is not None:
queryset = queryset.filter(serial=serial_number) 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: if in_stock is not None:
in_stock = str2bool(in_stock) in_stock = str2bool(in_stock)
@ -512,7 +512,7 @@ class StockList(generics.ListCreateAPIView):
queryset = queryset.exclude(StockItem.IN_STOCK_FILTER) queryset = queryset.exclude(StockItem.IN_STOCK_FILTER)
# Filter by 'allocated' patrs? # Filter by 'allocated' patrs?
allocated = self.request.query_params.get('allocated', None) allocated = params.get('allocated', None)
if allocated is not None: if allocated is not None:
allocated = str2bool(allocated) allocated = str2bool(allocated)
@ -531,8 +531,14 @@ class StockList(generics.ListCreateAPIView):
active = str2bool(active) active = str2bool(active)
queryset = queryset.filter(part__active=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? # 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: if part_id:
try: try: