mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add more options to StockList api
- Limit query results - Order by various fields
This commit is contained in:
parent
66e1b180e4
commit
949a541ee0
@ -626,7 +626,7 @@ class PartList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
queryset = queryset.filter(pk__in=parts_need_stock)
|
queryset = queryset.filter(pk__in=parts_need_stock)
|
||||||
|
|
||||||
# Limit choices
|
# Limit number of results
|
||||||
limit = params.get('limit', None)
|
limit = params.get('limit', None)
|
||||||
|
|
||||||
if limit is not None:
|
if limit is not None:
|
||||||
|
@ -808,6 +808,19 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
print("After error:", str(updated_after))
|
print("After error:", str(updated_after))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Limit number of results
|
||||||
|
limit = params.get('limit', None)
|
||||||
|
|
||||||
|
if limit is not None:
|
||||||
|
try:
|
||||||
|
limit = int(limit)
|
||||||
|
|
||||||
|
if limit > 0:
|
||||||
|
queryset = queryset[:limit]
|
||||||
|
|
||||||
|
except (ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
# Also ensure that we pre-fecth all the related items
|
# Also ensure that we pre-fecth all the related items
|
||||||
queryset = queryset.prefetch_related(
|
queryset = queryset.prefetch_related(
|
||||||
'part',
|
'part',
|
||||||
@ -815,8 +828,6 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
'location'
|
'location'
|
||||||
)
|
)
|
||||||
|
|
||||||
queryset = queryset.order_by('part__name')
|
|
||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
filter_backends = [
|
filter_backends = [
|
||||||
@ -828,6 +839,15 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
filter_fields = [
|
filter_fields = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
ordering_fields = [
|
||||||
|
'part__name',
|
||||||
|
'updated',
|
||||||
|
'stocktake_date',
|
||||||
|
'expiry_date',
|
||||||
|
]
|
||||||
|
|
||||||
|
ordering = ['part__name']
|
||||||
|
|
||||||
search_fields = [
|
search_fields = [
|
||||||
'serial',
|
'serial',
|
||||||
'batch',
|
'batch',
|
||||||
|
Loading…
Reference in New Issue
Block a user