diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 88df0a541e..1c1429cf0e 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -421,6 +421,16 @@ class StockFilter(rest_filters.FilterSet): else: return queryset.exclude(StockItem.EXPIRED_FILTER) + external = rest_filters.BooleanFilter(label=_('External Location'), method='filter_external') + + def filter_external(self, queryset, name, value): + """Filter by whether or not the stock item is located in an external location""" + + if str2bool(value): + return queryset.filter(location__external=True) + else: + return queryset.exclude(location__external=True) + in_stock = rest_filters.BooleanFilter(label='In Stock', method='filter_in_stock') def filter_in_stock(self, queryset, name, value): diff --git a/InvenTree/templates/js/translated/table_filters.js b/InvenTree/templates/js/translated/table_filters.js index 9eab6a1bb8..6eb5725e25 100644 --- a/InvenTree/templates/js/translated/table_filters.js +++ b/InvenTree/templates/js/translated/table_filters.js @@ -292,6 +292,10 @@ function getAvailableTableFilters(tableKey) { type: 'date', title: '{% trans "Expiry Date after" %}', }, + external: { + type: 'bool', + title: '{% trans "External Location" %}', + } }; // Optional filters if stock expiry functionality is enabled