From e9a1b579412da98559b6366997965da4f353a646 Mon Sep 17 00:00:00 2001 From: simonkuehling Date: Tue, 28 Feb 2023 02:22:27 +0100 Subject: [PATCH] Add unallocated quantity to StockItem renderer (#4425) * add unallocated quantity to StockItem renderer * introduce parameter to switch between total quantity and available quantity --- InvenTree/templates/js/translated/build.js | 1 + .../templates/js/translated/model_renderers.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js index fd9236994c..175781c67c 100644 --- a/InvenTree/templates/js/translated/build.js +++ b/InvenTree/templates/js/translated/build.js @@ -2296,6 +2296,7 @@ function allocateStockToBuild(build_id, part_id, bom_items, options={}) { render_part_detail: true, render_location_detail: true, render_pk: false, + render_available_quantity: true, auto_fill: true, auto_fill_filters: auto_fill_filters, onSelect: function(data, field, opts) { diff --git a/InvenTree/templates/js/translated/model_renderers.js b/InvenTree/templates/js/translated/model_renderers.js index 4c4e70122f..fb38e1345b 100644 --- a/InvenTree/templates/js/translated/model_renderers.js +++ b/InvenTree/templates/js/translated/model_renderers.js @@ -111,6 +111,12 @@ function renderStockItem(name, data, parameters={}, options={}) { location_detail = ` - (${data.location_detail.name})`; } + var render_available_quantity = false; + + if ('render_available_quantity' in parameters) { + render_available_quantity = parameters['render_available_quantity']; + } + var stock_detail = ''; if (data.quantity == 0) { @@ -119,7 +125,12 @@ function renderStockItem(name, data, parameters={}, options={}) { if (data.serial && data.quantity == 1) { stock_detail = `{% trans "Serial Number" %}: ${data.serial}`; } else { - stock_detail = `{% trans "Quantity" %}: ${data.quantity}`; + if (render_available_quantity) { + var available = data.quantity - data.allocated; + stock_detail = `{% trans "Available" %}: ${available}`; + } else { + stock_detail = `{% trans "Quantity" %}: ${data.quantity}`; + } } if (data.batch) {