From 402301e165e7a4a5911994547513383609cdc503 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 17:06:22 +1000 Subject: [PATCH 1/5] Add ability to filter stock items by "depleted" status --- InvenTree/stock/api.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 018b588c1f..023b0c6c4e 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -539,10 +539,21 @@ class StockList(generics.ListCreateAPIView): active = str2bool(active) queryset = queryset.filter(part__active=active) + # Filter by 'depleted' status + depleted = params.get('depleted', None) + + if depleted is not None: + depleted = str2bool(depleted) + + if depleted: + queryset = queryset.filter(quantity__lte=0) + else: + queryset = queryset.exclude(quantity__lte=0) + # Filter by internal part number IPN = params.get('IPN', None) - if IPN: + if IPN is not None: queryset = queryset.filter(part__IPN=IPN) # Does the client wish to filter by the Part ID? From 099f56e7798db12a45907ac286bdb959d400f854 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 17:08:18 +1000 Subject: [PATCH 2/5] Add "depleted" table filter --- InvenTree/templates/js/table_filters.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/InvenTree/templates/js/table_filters.html b/InvenTree/templates/js/table_filters.html index e2138ef6b3..affb97c1c5 100644 --- a/InvenTree/templates/js/table_filters.html +++ b/InvenTree/templates/js/table_filters.html @@ -47,6 +47,11 @@ function getAvailableTableFilters(tableKey) { title: '{% trans "Active parts" %}', description: '{% trans "Show stock for active parts" %}', }, + depleted: { + type: 'bool', + title: '{% trans "Depleted" %}', + description: '{% trans "Show stock items which are depleted" %}', + }, status: { options: stockCodes, title: '{% trans "Stock status" %}', From 96a3f2920df03252ed54d611498ab4d8f6065915 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 17:09:22 +1000 Subject: [PATCH 3/5] Stock table filters now arranged in alphabetical order --- InvenTree/templates/js/table_filters.html | 32 +++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/InvenTree/templates/js/table_filters.html b/InvenTree/templates/js/table_filters.html index affb97c1c5..aef430bf36 100644 --- a/InvenTree/templates/js/table_filters.html +++ b/InvenTree/templates/js/table_filters.html @@ -32,35 +32,30 @@ function getAvailableTableFilters(tableKey) { // Filters for the "Stock" table if (tableKey == 'stock') { return { - in_stock: { + active: { type: 'bool', - title: '{% trans "In Stock" %}', - description: '{% trans "Show items which are in stock" %}', + title: '{% trans "Active parts" %}', + description: '{% trans "Show stock for active parts" %}', + }, + allocated: { + type: 'bool', + title: '{% trans "Is allocated" %}', + description: '{% trans "Item has been alloacted" %}', }, cascade: { type: 'bool', title: '{% trans "Include sublocations" %}', description: '{% trans "Include stock in sublocations" %}', }, - active: { - type: 'bool', - title: '{% trans "Active parts" %}', - description: '{% trans "Show stock for active parts" %}', - }, depleted: { type: 'bool', title: '{% trans "Depleted" %}', description: '{% trans "Show stock items which are depleted" %}', }, - status: { - options: stockCodes, - title: '{% trans "Stock status" %}', - description: '{% trans "Stock status" %}', - }, - allocated: { + in_stock: { type: 'bool', - title: '{% trans "Is allocated" %}', - description: '{% trans "Item has been alloacted" %}', + title: '{% trans "In Stock" %}', + description: '{% trans "Show items which are in stock" %}', }, serialized: { type: 'bool', @@ -74,6 +69,11 @@ function getAvailableTableFilters(tableKey) { title: "{% trans "Serial number LTE" %}", description: "{% trans "Serial number less than or equal to" %}", }, + status: { + options: stockCodes, + title: '{% trans "Stock status" %}', + description: '{% trans "Stock status" %}', + }, }; } From bc3fda71a436dac7129d5f739f4ab0d31bcea627 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 17:11:50 +1000 Subject: [PATCH 4/5] Display "depleted" label next to depleted stock --- InvenTree/templates/js/stock.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/InvenTree/templates/js/stock.html b/InvenTree/templates/js/stock.html index adaf07b4f6..f06615f2f5 100644 --- a/InvenTree/templates/js/stock.html +++ b/InvenTree/templates/js/stock.html @@ -468,6 +468,10 @@ function loadStockTable(table, options) { html += ``; } + if (row.quantity <= 0) { + html += `{% trans "Depleted" %}`; + } + return html; } }, From ad116813696cba9e2de486d903bdc1f05ce6288b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 17:15:08 +1000 Subject: [PATCH 5/5] Custom filter tag for company stock listing --- InvenTree/company/templates/company/detail_stock.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/InvenTree/company/templates/company/detail_stock.html b/InvenTree/company/templates/company/detail_stock.html index c33179d454..e994d5834b 100644 --- a/InvenTree/company/templates/company/detail_stock.html +++ b/InvenTree/company/templates/company/detail_stock.html @@ -26,7 +26,8 @@ }, buttons: [ '#stock-options', - ] + ], + filterKey: "companystock", }); $("#stock-export").click(function() {