mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 21:15:41 +00:00
Stock API filtering fix (#4350)
* Improve filtering options for StockItem list - Make use of StockFilter introspection * Remove outdated filter * remove outdated "max_results" parameter * Fix cascade issue for stocklist API * Add relationship filters to the StockItemFilter * Fix filtering by 'status' and 'allocated' * Refactor 'customer' and 'expired' filters * Cleanup * Adds unit test for top-level stock location filtering
This commit is contained in:
@ -1342,15 +1342,11 @@ class PartList(APIDownloadMixin, ListCreateAPI):
|
||||
# Does the user wish to filter by category?
|
||||
cat_id = params.get('category', None)
|
||||
|
||||
if cat_id is None:
|
||||
# No category filtering if category is not specified
|
||||
pass
|
||||
|
||||
else:
|
||||
if cat_id is not None:
|
||||
# Category has been specified!
|
||||
if isNull(cat_id):
|
||||
# A 'null' category is the top-level category
|
||||
if cascade is False:
|
||||
if not cascade:
|
||||
# Do not cascade, only list parts in the top-level category
|
||||
queryset = queryset.filter(category=None)
|
||||
|
||||
@ -1393,20 +1389,6 @@ class PartList(APIDownloadMixin, ListCreateAPI):
|
||||
|
||||
queryset = queryset.filter(pk__in=parts_needed_to_complete_builds)
|
||||
|
||||
# Optionally limit the maximum number of returned results
|
||||
# e.g. for displaying "recent part" list
|
||||
max_results = params.get('max_results', None)
|
||||
|
||||
if max_results is not None:
|
||||
try:
|
||||
max_results = int(max_results)
|
||||
|
||||
if max_results > 0:
|
||||
queryset = queryset[:max_results]
|
||||
|
||||
except (ValueError):
|
||||
pass
|
||||
|
||||
return queryset
|
||||
|
||||
filter_backends = [
|
||||
|
Reference in New Issue
Block a user