2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-30 12:36:45 +00:00

Fix for 'available' filter (#4952) (#4954)

- Available filter also requires "in stock"

(cherry picked from commit c0dafe155fbaa872110bc53c5ce190b3fde53ada)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
github-actions[bot] 2023-06-02 17:06:09 +10:00 committed by GitHub
parent 970714a76f
commit 5b6d999091
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -434,7 +434,8 @@ class StockFilter(rest_filters.FilterSet):
"""
if str2bool(value):
# The 'quantity' field is greater than the calculated 'allocated' field
return queryset.filter(Q(quantity__gt=F('allocated')))
# Note that the item must also be "in stock"
return queryset.filter(StockItem.IN_STOCK_FILTER).filter(Q(quantity__gt=F('allocated')))
else:
# The 'quantity' field is less than (or equal to) the calculated 'allocated' field
return queryset.filter(Q(quantity__lte=F('allocated')))