Add ability to filter stock by supplier

This commit is contained in:
Oliver Walters 2019-05-16 21:01:34 +10:00
parent b4df96aaee
commit c1224048ad

View File

@ -242,6 +242,7 @@ class StockList(generics.ListCreateAPIView):
Additional query parameters are available:
- location: Filter stock by location
- category: Filter by parts belonging to a certain category
- supplier: Filter by supplier
"""
def get_queryset(self):
@ -275,6 +276,12 @@ class StockList(generics.ListCreateAPIView):
except PartCategory.DoesNotExist:
pass
# Filter by supplier
supplier_id = self.request.query_params.get('supplier', None)
if supplier_id:
stock_list = stock_list.filter(supplier_part__supplier=supplier_id)
return stock_list
serializer_class = StockItemSerializer