diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 2667352515..0238a62c63 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -289,20 +289,35 @@ class StockLocationList(generics.ListCreateAPIView): queryset = super().get_queryset() - loc_id = self.request.query_params.get('parent', None) + params = self.request.query_params - if loc_id is not None: + cascade = str2bool(params.get('cascade', False)) - # Look for top-level locations - if isNull(loc_id): + loc_id = params.get('parent', None) + + # Look for top-level locations + if isNull(loc_id): + + # If we allow "cascade" at the top-level, this essentially means *all* locations + if not cascade: queryset = queryset.filter(parent=None) - - else: - try: - loc_id = int(loc_id) - queryset = queryset.filter(parent=loc_id) - except ValueError: - pass + + else: + + try: + location = StockLocation.objects.get(pk=loc_id) + + # All sub-locations to be returned too? + if cascade: + parents = location.get_descendants(include_self=True) + parent_ids = [p.id for p in parents] + queryset = queryset.filter(parent__in=parent_ids) + + else: + queryset = queryset.filter(parent=location) + + except (ValueError, StockLocation.DoesNotExist): + pass return queryset diff --git a/InvenTree/stock/templates/stock/sublocation.html b/InvenTree/stock/templates/stock/sublocation.html index b8b32328a2..c5a6062064 100644 --- a/InvenTree/stock/templates/stock/sublocation.html +++ b/InvenTree/stock/templates/stock/sublocation.html @@ -15,7 +15,16 @@

{% trans "Sublocations" %}

-
+ +
+
+ +
+
+ +
+
+
{% endblock %} diff --git a/InvenTree/templates/js/stock.js b/InvenTree/templates/js/stock.js index 990acf65ba..c10e432f5e 100644 --- a/InvenTree/templates/js/stock.js +++ b/InvenTree/templates/js/stock.js @@ -957,6 +957,12 @@ function loadStockLocationTable(table, options) { switchable: true, sortable: false, }, + { + field: 'pathstring', + title: '{% trans "Path" %}', + switchable: true, + sortable: false, + }, { field: 'items', title: '{% trans "Stock Items" %}', diff --git a/InvenTree/templates/js/table_filters.js b/InvenTree/templates/js/table_filters.js index ba73244c74..775f0d9803 100644 --- a/InvenTree/templates/js/table_filters.js +++ b/InvenTree/templates/js/table_filters.js @@ -62,6 +62,28 @@ function getAvailableTableFilters(tableKey) { }; } + // Filters for "stock location" table + if (tableKey == "location") { + return { + cascade: { + type: 'bool', + title: '{% trans "Include sublocations" %}', + description: '{% trans "Include locations" %}', + } + }; + } + + // Filters for "part category" table + if (tableKey == "category") { + return { + cascade: { + type: 'bool', + title: '{% trans "Include subcategories" %}', + description: '{% trans "Include subcategories" %}', + } + }; + } + // Filters for the "customer stock" table (really a subset of "stock") if (tableKey == "customerstock") { return {