From 15253435af8c2ddf2aa99d159b1670cfea0e5ebc Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 5 Apr 2022 00:02:11 +1000 Subject: [PATCH 1/4] Adjustments for partStockLabel function --- InvenTree/templates/js/translated/part.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index 1c66c32b6e..7a08d534df 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -491,13 +491,16 @@ function duplicateBom(part_id, options={}) { } +/* + * Construct a "badge" label showing stock information for this particular part + */ function partStockLabel(part, options={}) { if (part.in_stock) { // There IS stock available for this part // Is stock "low" (below the 'minimum_stock' quantity)? - if (part.minimum_stock && part.minimum_stock > part.in_stock) { + if ((part.minimum_stock > 0) && (part.minimum_stock > part.in_stock)) { return `{% trans "Low stock" %}: ${part.in_stock}${part.units}`; } else if (part.unallocated_stock == 0) { if (part.ordering) { @@ -507,11 +510,15 @@ function partStockLabel(part, options={}) { // There is no available stock, but stock is being built return `{% trans "Building" %}: ${part.building}${part.units}`; } else { - // There is no available stock - return `{% trans "Available" %}: 0/${part.in_stock}${part.units}`; + // There is no available stock at all + return `{% trans "No stock available" %}`; } - } else { + } else if (part.unallocated_stock < part.in_stock) { + // Unallocated quanttiy is less than total quantity return `{% trans "Available" %}: ${part.unallocated_stock}/${part.in_stock}${part.units}`; + } else { + // Stock is completely available + return `{% trans "Available" %}: ${part.unallocated_stock}${part.units}`; } } else { // There IS NO stock available for this part From 58003bc2cb2211df046881a1cc976148081cf38e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 5 Apr 2022 00:27:37 +1000 Subject: [PATCH 2/4] Refactor model renderer functions --- InvenTree/templates/js/translated/build.js | 2 +- .../js/translated/model_renderers.js | 56 +++++++++---------- InvenTree/templates/js/translated/search.js | 4 ++ 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js index 201d3c5c9f..d4db965ebd 100644 --- a/InvenTree/templates/js/translated/build.js +++ b/InvenTree/templates/js/translated/build.js @@ -1746,7 +1746,7 @@ function allocateStockToBuild(build_id, part_id, bom_items, options={}) { required: true, render_part_detail: true, render_location_detail: true, - render_stock_id: false, + render_pk: false, 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 7be6c954c2..8c98fa35de 100644 --- a/InvenTree/templates/js/translated/model_renderers.js +++ b/InvenTree/templates/js/translated/model_renderers.js @@ -31,6 +31,24 @@ */ +// Should the ID be rendered for this string +function renderId(title, pk, parameters={}) { + + // Default = true + var render = true; + + if ('render_pk' in parameters) { + render = parameters['render_pk']; + } + + if (render) { + return `${title}: ${pk}`; + } else { + return ''; + } +} + + // Renderer for "Company" model // eslint-disable-next-line no-unused-vars function renderCompany(name, data, parameters={}, options={}) { @@ -39,7 +57,7 @@ function renderCompany(name, data, parameters={}, options={}) { html += `${data.name} - ${data.description}`; - html += `{% trans "Company ID" %}: ${data.pk}`; + html += renderId('{% trans "Company ID" %}', data.pk, parameters); return html; } @@ -67,18 +85,6 @@ function renderStockItem(name, data, parameters={}, options={}) { part_detail = `${data.part_detail.full_name} - `; } - var render_stock_id = true; - - if ('render_stock_id' in parameters) { - render_stock_id = parameters['render_stock_id']; - } - - var stock_id = ''; - - if (render_stock_id) { - stock_id = `{% trans "Stock ID" %}: ${data.pk}`; - } - var render_location_detail = false; if ('render_location_detail' in parameters) { @@ -88,7 +94,7 @@ function renderStockItem(name, data, parameters={}, options={}) { var location_detail = ''; if (render_location_detail && data.location_detail) { - location_detail = ` - (${data.location_detail.name})`; + location_detail = ` - (${data.location_detail.name})`; } var stock_detail = ''; @@ -103,7 +109,10 @@ function renderStockItem(name, data, parameters={}, options={}) { var html = ` - ${part_detail}${stock_detail}${location_detail}${stock_id} + ${part_detail} + ${stock_detail} + ${location_detail} + ${renderId('{% trans "Stock ID" %}', data.pk, parameters)} `; @@ -183,7 +192,7 @@ function renderPart(name, data, parameters={}, options={}) { ${stock_data} ${extra} - {% trans "Part ID" %}: ${data.pk} + ${renderId('{% trans "Part ID" $}', data.pk, parameters)} `; @@ -245,13 +254,7 @@ function renderPurchaseOrder(name, data, parameters={}, options={}) { html += ` - ${data.description}`; } - html += ` - - - {% trans "Order ID" %}: ${data.pk} - - - `; + html += renderId('{% trans "Order ID" %}', data.pk, parameters); return html; } @@ -277,12 +280,7 @@ function renderSalesOrder(name, data, parameters={}, options={}) { html += ` - ${data.description}`; } - html += ` - - - {% trans "Order ID" %}: ${data.pk} - - `; + html += renderId('{% trans "Order ID" %}', data.pk, parameters); return html; } diff --git a/InvenTree/templates/js/translated/search.js b/InvenTree/templates/js/translated/search.js index 8900007c31..c0c1a07db7 100644 --- a/InvenTree/templates/js/translated/search.js +++ b/InvenTree/templates/js/translated/search.js @@ -132,6 +132,7 @@ function updateSearch() { renderStockItem, { url: '/stock/item', + render_location_detail: true, } ); } @@ -232,6 +233,9 @@ function addSearchQuery(key, title, query_url, query_params, render_func, render query_params.offset = 0; query_params.limit = user_settings.SEARCH_PREVIEW_RESULTS; + // Do not display "pk" value for search results + render_params.render_pk = false; + // Add the result group to the panel $('#offcanvas-search').find('#search-results').append(`
From 0908aa8c8cd5e35abad53ee8d8a052fc65720ce2 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 5 Apr 2022 00:31:44 +1000 Subject: [PATCH 3/4] Allow sorting of part table by unallocated_stock --- InvenTree/part/api.py | 1 + InvenTree/templates/js/translated/part.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index f7bb81520d..e1b0dda61f 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -1348,6 +1348,7 @@ class PartList(generics.ListCreateAPIView): 'creation_date', 'IPN', 'in_stock', + 'unallocated_stock', 'category', ] diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index 7a08d534df..d5ab193429 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -1384,7 +1384,7 @@ function loadPartTable(table, url, options={}) { link = '?display=build-orders'; } else { // There is no available stock - value = `0{% trans "Not available" %}`; + value = `0{% trans "No stock available" %}`; } } } else { From c93f9c94f3e007a4511d191438aac1747b911db8 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 5 Apr 2022 00:33:54 +1000 Subject: [PATCH 4/4] Change column title --- InvenTree/templates/js/translated/part.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index d5ab193429..08b258fdc2 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -1362,7 +1362,7 @@ function loadPartTable(table, url, options={}) { col = { field: 'unallocated_stock', - title: '{% trans "Available" %}', + title: '{% trans "Stock" %}', searchable: false, formatter: function(value, row) { var link = '?display=part-stock';