Fix for 'available' filter (#4952)

- Available filter also requires "in stock"
This commit is contained in:
Oliver 2023-06-02 16:37:16 +10:00 committed by GitHub
parent 1df97a7607
commit c0dafe155f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -444,7 +444,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')))