From 36cf614aed38bdaf91bcdd0ee7191d6f12ea08ea Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 18 Jul 2021 21:11:53 +1000 Subject: [PATCH 1/3] Add "level" to PartCategory serializer - Also use tree ordering by default --- InvenTree/part/api.py | 10 +++++++++- InvenTree/part/serializers.py | 7 +++++-- InvenTree/templates/js/model_renderers.js | 8 +++----- 3 files changed, 17 insertions(+), 8 deletions(-) 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/templates/js/model_renderers.js b/InvenTree/templates/js/model_renderers.js index caa209dc90..3b1b9c82d9 100644 --- a/InvenTree/templates/js/model_renderers.js +++ b/InvenTree/templates/js/model_renderers.js @@ -154,7 +154,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 +164,6 @@ function renderPartCategory(name, data, parameters, options) { html += `{% trans "Category ID" %}: ${data.pk}`; - if (data.pathstring) { - html += `

${data.pathstring}

`; - } - return html; } From 753fe9c80f7ec826eb17ddfeda4b69391b6dff70 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 18 Jul 2021 21:15:51 +1000 Subject: [PATCH 2/3] Ordering and rendering for StockLocation --- InvenTree/stock/api.py | 9 +++++++++ InvenTree/stock/serializers.py | 3 +++ InvenTree/templates/js/model_renderers.js | 8 +++----- 3 files changed, 15 insertions(+), 5 deletions(-) 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 3b1b9c82d9..257d296eff 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; } From c33cfe95039e3762a31a0695554f16b8ea2bcf3f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 18 Jul 2021 21:17:03 +1000 Subject: [PATCH 3/3] Small rendering improvements --- InvenTree/templates/js/model_renderers.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/InvenTree/templates/js/model_renderers.js b/InvenTree/templates/js/model_renderers.js index 257d296eff..ddb4897d8d 100644 --- a/InvenTree/templates/js/model_renderers.js +++ b/InvenTree/templates/js/model_renderers.js @@ -67,9 +67,9 @@ function renderStockItem(name, data, parameters, options) { // Renderer for "StockLocation" model function renderStockLocation(name, data, parameters, options) { - var level = '-'.repeat(data.level); + var level = '- '.repeat(data.level); - var html = `${level} ${data.pathstring}`; + var html = `${level}${data.pathstring}`; if (data.description) { html += ` - ${data.description}`; @@ -152,9 +152,9 @@ function renderOwner(name, data, parameters, options) { // Renderer for "PartCategory" model function renderPartCategory(name, data, parameters, options) { - var level = '-'.repeat(data.level); + var level = '- '.repeat(data.level); - var html = `${level} ${data.pathstring}`; + var html = `${level}${data.pathstring}`; if (data.description) { html += ` - ${data.description}`;