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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 0 deletions

View File

@ -7,8 +7,12 @@ INVENTREE_API_VERSION = 61
"""
Increment this API version number whenever there is a significant change to the API that any clients need to know about
v63 -> 2022-07-06 : https://github.com/inventree/InvenTree/pull/3301
- Allow BOM List API endpoint to be filtered by "available_stock" paramater
v62 -> 2022-07-05 : https://github.com/inventree/InvenTree/pull/3296
- Allows search on BOM List API endpoint
- Allows ordering on BOM List API endpoint
v61 -> 2022-06-12 : https://github.com/inventree/InvenTree/pull/3183
- Migrate the "Convert Stock Item" form class to use the API

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.

View File

@ -59,6 +59,10 @@ function getAvailableTableFilters(tableKey) {
type: 'bool',
title: '{% trans "Assembled Part" %}',
},
available_stock: {
type: 'bool',
title: '{% trans "Has Available Stock" %}',
},
validated: {
type: 'bool',
title: '{% trans "Validated" %}',