2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Allow BOM table to be filtered by "stock available" parameter (#3301)

* Allow BOM table to be filtered by "stock available" parameter

* Update API version info

* PEP fixes
This commit is contained in:
Oliver
2022-07-06 15:28:44 +10:00
committed by GitHub
parent 412fdf246a
commit cc8238b790
3 changed files with 22 additions and 0 deletions

View File

@ -1531,6 +1531,20 @@ class BomFilter(rest_filters.FilterSet):
return queryset
available_stock = rest_filters.BooleanFilter(label="Has available stock", method="filter_available_stock")
def filter_available_stock(self, queryset, name, value):
"""Filter the queryset based on whether each line item has any available stock"""
value = str2bool(value)
if value:
queryset = queryset.filter(available_stock__gt=0)
else:
queryset = queryset.filter(available_stock=0)
return queryset
class BomList(ListCreateDestroyAPIView):
"""API endpoint for accessing a list of BomItem objects.