diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 04a37e5fff..12bfd2de1d 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -626,7 +626,7 @@ class PartList(generics.ListCreateAPIView): queryset = queryset.filter(pk__in=parts_need_stock) - # Limit choices + # Limit number of results limit = params.get('limit', None) if limit is not None: diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 4e532b90b7..75b0d9de3b 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -808,6 +808,19 @@ class StockList(generics.ListCreateAPIView): print("After error:", str(updated_after)) 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 queryset = queryset.prefetch_related( 'part', @@ -815,8 +828,6 @@ class StockList(generics.ListCreateAPIView): 'location' ) - queryset = queryset.order_by('part__name') - return queryset filter_backends = [ @@ -828,6 +839,15 @@ class StockList(generics.ListCreateAPIView): filter_fields = [ ] + ordering_fields = [ + 'part__name', + 'updated', + 'stocktake_date', + 'expiry_date', + ] + + ordering = ['part__name'] + search_fields = [ 'serial', 'batch',