Skip to content

Commit

Permalink
Consumed filter (#8574)
Browse files Browse the repository at this point in the history
* Add API filter for 'consumed' status

* Add filter to table

* Bump API vession
  • Loading branch information
SchrodingersGat authored Nov 27, 2024
1 parent a48d23b commit 28ea275
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/backend/InvenTree/InvenTree/api_version.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""InvenTree API version information."""

# InvenTree API version
INVENTREE_API_VERSION = 287
INVENTREE_API_VERSION = 288

"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""


INVENTREE_API_TEXT = """
v288 - 2024-11-27 : https://github.com/inventree/InvenTree/pull/8574
- Adds "consumed" filter to StockItem API
v287 - 2024-11-27 : https://github.com/inventree/InvenTree/pull/8571
- Adds ability to set stock status when returning items from a customer
Expand Down
17 changes: 16 additions & 1 deletion src/backend/InvenTree/stock/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ def filter_part(self, queryset, name, part):
field_name='part__name',
lookup_expr='iexact',
)

name_contains = rest_filters.CharFilter(
label=_('Part name contains (case insensitive)'),
field_name='part__name',
Expand All @@ -540,11 +541,13 @@ def filter_part(self, queryset, name, part):
field_name='part__IPN',
lookup_expr='iexact',
)

IPN_contains = rest_filters.CharFilter(
label=_('Part IPN contains (case insensitive)'),
field_name='part__IPN',
lookup_expr='icontains',
)

IPN_regex = rest_filters.CharFilter(
label=_('Part IPN (regex)'), field_name='part__IPN', lookup_expr='iregex'
)
Expand All @@ -553,12 +556,14 @@ def filter_part(self, queryset, name, part):
assembly = rest_filters.BooleanFilter(
label=_('Assembly'), field_name='part__assembly'
)

active = rest_filters.BooleanFilter(label=_('Active'), field_name='part__active')
salable = rest_filters.BooleanFilter(label=_('Salable'), field_name='part__salable')

min_stock = rest_filters.NumberFilter(
label=_('Minimum stock'), field_name='quantity', lookup_expr='gte'
)

max_stock = rest_filters.NumberFilter(
label=_('Maximum stock'), field_name='quantity', lookup_expr='lte'
)
Expand Down Expand Up @@ -695,8 +700,18 @@ def filter_tracked(self, queryset, name, value):

return queryset.filter(q_batch).filter(q_serial).distinct()

consumed = rest_filters.BooleanFilter(
label=_('Consumed by Build Order'), method='filter_consumed'
)

def filter_consumed(self, queryset, name, value):
"""Filter by whether the stock item has been consumed by a build order."""
if str2bool(value):
return queryset.filter(consumed_by__isnull=False)
return queryset.filter(consumed_by__isnull=True)

installed = rest_filters.BooleanFilter(
label='Installed in other stock item', method='filter_installed'
label=_('Installed in other stock item'), method='filter_installed'
)

def filter_installed(self, queryset, name, value):
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/src/tables/stock/StockItemTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ function stockItemTableFilters({
label: t`Include Variants`,
description: t`Include stock items for variant parts`
},
{
name: 'consumed',
label: t`Consumed`,
description: t`Show items which have been consumed by a build order`
},
{
name: 'installed',
label: t`Installed`,
Expand Down

0 comments on commit 28ea275

Please sign in to comment.