diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py
index ab946b7dcb..0ce7c7d5a6 100644
--- a/InvenTree/part/api.py
+++ b/InvenTree/part/api.py
@@ -60,28 +60,40 @@ class CategoryList(generics.ListCreateAPIView):
queryset = PartCategory.objects.all()
serializer_class = part_serializers.CategorySerializer
- def get_queryset(self):
+ def filter_queryset(self, queryset):
"""
Custom filtering:
- Allow filtering by "null" parent to retrieve top-level part categories
"""
- cat_id = self.request.query_params.get('parent', None)
+ queryset = super().filter_queryset(queryset)
- queryset = super().get_queryset()
+ params = self.request.query_params
- if cat_id is not None:
+ cat_id = params.get('parent', None)
+
+ cascade = str2bool(params.get('cascade', False))
+
+ # Look for top-level categories
+ if isNull(cat_id):
- # Look for top-level categories
- if isNull(cat_id):
+ if not cascade:
queryset = queryset.filter(parent=None)
-
- else:
- try:
- cat_id = int(cat_id)
- queryset = queryset.filter(parent=cat_id)
- except ValueError:
- pass
+
+ else:
+ try:
+ category = PartCategory.objects.get(pk=cat_id)
+
+ if cascade:
+ parents = category.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=category)
+
+ except (ValueError, PartCategory.DoesNotExist):
+ pass
return queryset
diff --git a/InvenTree/part/templates/part/category_subcategory.html b/InvenTree/part/templates/part/category_subcategory.html
deleted file mode 100644
index e45e01499a..0000000000
--- a/InvenTree/part/templates/part/category_subcategory.html
+++ /dev/null
@@ -1,42 +0,0 @@
-{% extends "part/category.html" %}
-
-{% load i18n %}
-{% load inventree_extras %}
-{% load static %}
-
-{% block menubar %}
-{% include 'part/category_navbar.html' with tab='subcategories' %}
-{% endblock %}
-
-{% block category_content %}
-
-
-
-
-
{% trans "Subcategories" %}
-
-
-
-
-
-{% endblock %}
-
-{% block js_ready %}
-{{ block.super }}
-
- enableNavbar({
- label: 'category',
- toggleId: '#category-menu-toggle',
- });
-
- loadPartCategoryTable($('#subcategory-table'), {
- params: {
- {% if category %}
- parent: {{ category.pk }}
- {% else %}
- parent: 'null'
- {% endif %}
- }
- });
-
-{% endblock %}
diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py
index b8f80d4845..b90b11b568 100644
--- a/InvenTree/part/urls.py
+++ b/InvenTree/part/urls.py
@@ -94,7 +94,7 @@ category_urls = [
url(r'^new/', views.CategoryCreate.as_view(), name='category-create'),
# Top level subcategory display
- url(r'^subcategory/', views.PartIndex.as_view(template_name='part/category_subcategory.html'), name='category-index-subcategory'),
+ url(r'^subcategory/', views.PartIndex.as_view(template_name='part/subcategory.html'), name='category-index-subcategory'),
# Category detail views
url(r'(?P\d+)/', include([
@@ -102,7 +102,7 @@ category_urls = [
url(r'^delete/', views.CategoryDelete.as_view(), name='category-delete'),
url(r'^parameters/', include(category_parameter_urls)),
- url(r'^subcategory/', views.CategoryDetail.as_view(template_name='part/category_subcategory.html'), name='category-subcategory'),
+ url(r'^subcategory/', views.CategoryDetail.as_view(template_name='part/subcategory.html'), name='category-subcategory'),
url(r'^parametric/', views.CategoryParametric.as_view(), name='category-parametric'),
# Anything else
diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py
index 0238a62c63..08599ea858 100644
--- a/InvenTree/stock/api.py
+++ b/InvenTree/stock/api.py
@@ -281,13 +281,13 @@ class StockLocationList(generics.ListCreateAPIView):
queryset = StockLocation.objects.all()
serializer_class = LocationSerializer
- def get_queryset(self):
+ def filter_queryset(self, queryset):
"""
Custom filtering:
- Allow filtering by "null" parent to retrieve top-level stock locations
"""
- queryset = super().get_queryset()
+ queryset = super().filter_queryset(queryset)
params = self.request.query_params
diff --git a/InvenTree/stock/templates/stock/sublocation.html b/InvenTree/stock/templates/stock/sublocation.html
index d38539f842..24b034449e 100644
--- a/InvenTree/stock/templates/stock/sublocation.html
+++ b/InvenTree/stock/templates/stock/sublocation.html
@@ -32,6 +32,7 @@
+
diff --git a/InvenTree/templates/js/part.js b/InvenTree/templates/js/part.js
index b7e052ce72..e3e7190952 100644
--- a/InvenTree/templates/js/part.js
+++ b/InvenTree/templates/js/part.js
@@ -546,6 +546,7 @@ function loadPartCategoryTable(table, options) {
title: '{% trans "Select" %}',
searchable: false,
switchable: false,
+ visible: false,
},
{
field: 'name',
@@ -565,6 +566,12 @@ function loadPartCategoryTable(table, options) {
switchable: true,
sortable: false,
},
+ {
+ field: 'pathstring',
+ title: '{% trans "Path" %}',
+ switchable: true,
+ sortable: false,
+ },
{
field: 'parts',
title: '{% trans "Parts" %}',