diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 9abee816fa..3a5fee4e3d 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -118,9 +118,17 @@ class CategoryList(generics.ListCreateAPIView): ordering_fields = [ 'name', + 'level', + 'tree_id', + 'lft', ] - ordering = 'name' + # Use hierarchical ordering by default + ordering = [ + 'tree_id', + 'lft', + 'name' + ] search_fields = [ 'name', diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index 6627639bca..92dda58590 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -32,6 +32,8 @@ class CategorySerializer(InvenTreeModelSerializer): parts = serializers.IntegerField(source='item_count', read_only=True) + level = serializers.IntegerField(read_only=True) + class Meta: model = PartCategory fields = [ @@ -40,10 +42,11 @@ class CategorySerializer(InvenTreeModelSerializer): 'description', 'default_location', 'default_keywords', - 'pathstring', - 'url', + 'level', 'parent', 'parts', + 'pathstring', + 'url', ] diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 08e948607a..70ab939ff1 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -363,6 +363,15 @@ class StockLocationList(generics.ListCreateAPIView): ordering_fields = [ 'name', 'items', + 'level', + 'tree_id', + 'lft', + ] + + ordering = [ + 'tree_id', + 'lft', + 'name', ] diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index 38301bdd1f..a175787c63 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -260,12 +260,15 @@ class LocationSerializer(InvenTreeModelSerializer): items = serializers.IntegerField(source='item_count', read_only=True) + level = serializers.IntegerField(read_only=True) + class Meta: model = StockLocation fields = [ 'pk', 'url', 'name', + 'level', 'description', 'parent', 'pathstring', diff --git a/InvenTree/templates/js/model_renderers.js b/InvenTree/templates/js/model_renderers.js index caa209dc90..ddb4897d8d 100644 --- a/InvenTree/templates/js/model_renderers.js +++ b/InvenTree/templates/js/model_renderers.js @@ -67,7 +67,9 @@ function renderStockItem(name, data, parameters, options) { // Renderer for "StockLocation" model function renderStockLocation(name, data, parameters, options) { - var html = `${data.name}`; + var level = '- '.repeat(data.level); + + var html = `${level}${data.pathstring}`; if (data.description) { html += ` - ${data.description}`; @@ -75,10 +77,6 @@ function renderStockLocation(name, data, parameters, options) { html += `{% trans "Location ID" %}: ${data.pk}`; - if (data.pathstring) { - html += `

${data.pathstring}

`; - } - return html; } @@ -154,7 +152,9 @@ function renderOwner(name, data, parameters, options) { // Renderer for "PartCategory" model function renderPartCategory(name, data, parameters, options) { - var html = `${data.name}`; + var level = '- '.repeat(data.level); + + var html = `${level}${data.pathstring}`; if (data.description) { html += ` - ${data.description}`; @@ -162,10 +162,6 @@ function renderPartCategory(name, data, parameters, options) { html += `{% trans "Category ID" %}: ${data.pk}`; - if (data.pathstring) { - html += `

${data.pathstring}

`; - } - return html; }