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/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/part.js b/InvenTree/templates/js/translated/part.js
index 1c66c32b6e..08b258fdc2 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 ` `;
} 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 ` `;
} else {
- // There is no available stock
- return ` `;
+ // There is no available stock at all
+ return ` `;
}
- } else {
+ } else if (part.unallocated_stock < part.in_stock) {
+ // Unallocated quanttiy is less than total quantity
return ` `;
+ } else {
+ // Stock is completely available
+ return ` `;
}
} else {
// There IS NO stock available for this part
@@ -1355,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';
@@ -1377,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 {
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(`