diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index 32f359f5f2..86242c65af 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -12,11 +12,14 @@ import common.models INVENTREE_SW_VERSION = "0.7.0 dev" # InvenTree API version -INVENTREE_API_VERSION = 38 +INVENTREE_API_VERSION = 39 """ Increment this API version number whenever there is a significant change to the API that any clients need to know about +v39 -> 2022-04-18 + - Adds ability to filter StockItem list by "has_batch" parameter + v38 -> 2022-04-14 : https://github.com/inventree/InvenTree/pull/2828 - Adds the ability to include stock test results for "installed items" diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 15ddfd9c07..e176948599 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -410,6 +410,20 @@ class StockFilter(rest_filters.FilterSet): return queryset + has_batch = rest_filters.BooleanFilter(label='Has batch code', method='filter_has_batch') + + def filter_has_batch(self, queryset, name, value): + """ + Filter by whether the StockItem has a batch code (or not) + """ + + if str2bool(value): + queryset = queryset.exclude(batch=None) + else: + queryset = queryset.filter(batch=None) + + return queryset + installed = rest_filters.BooleanFilter(label='Installed in other stock item', method='filter_installed') def filter_installed(self, queryset, name, value): diff --git a/InvenTree/templates/js/translated/model_renderers.js b/InvenTree/templates/js/translated/model_renderers.js index 43a2fc624c..186349b5ac 100644 --- a/InvenTree/templates/js/translated/model_renderers.js +++ b/InvenTree/templates/js/translated/model_renderers.js @@ -99,14 +99,22 @@ function renderStockItem(name, data, parameters={}, options={}) { var stock_detail = ''; - if (data.serial && data.quantity == 1) { - stock_detail = `{% trans "Serial Number" %}: ${data.serial}`; - } else if (data.quantity == 0) { + if (data.quantity == 0) { stock_detail = `{% trans "No Stock"% }`; } else { - stock_detail = `{% trans "Quantity" %}: ${data.quantity}`; + if (data.serial && data.quantity == 1) { + stock_detail = `{% trans "Serial Number" %}: ${data.serial}`; + } else { + stock_detail = `{% trans "Quantity" %}: ${data.quantity}`; + } + + if (data.batch != null) { + stock_detail += ` - {% trans "Batch" %}: ${data.batch}`; + } } + + var html = ` ${part_detail} diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index 9f9400c924..42ed04265d 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -964,6 +964,10 @@ function adjustStock(action, items, options={}) { quantity = `#${item.serial}`; } + if (item.batch != null) { + quantity += ` - {% trans "Batch" %}: ${item.batch}`; + } + var actionInput = ''; if (actionTitle != null) { diff --git a/InvenTree/templates/js/translated/table_filters.js b/InvenTree/templates/js/translated/table_filters.js index 8eca911f08..303d484788 100644 --- a/InvenTree/templates/js/translated/table_filters.js +++ b/InvenTree/templates/js/translated/table_filters.js @@ -234,6 +234,10 @@ function getAvailableTableFilters(tableKey) { title: '{% trans "Stock status" %}', description: '{% trans "Stock status" %}', }, + has_batch: { + title: '{% trans "Has batch code" %}', + type: 'bool', + }, batch: { title: '{% trans "Batch" %}', description: '{% trans "Batch code" %}',