2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 04:55:44 +00:00

Stock available (#3057)

* Fix display of stock labels

- If 'shipped' or 'installed', don't display 'allocated' flag

* Switch stock item data around

* Add 'available' and 'allocation' information to the StockItem detail page

- Cache some context data to the view renderer

* Stock table now also displays allocation informatoin
This commit is contained in:
Oliver
2022-05-24 15:35:04 +10:00
committed by GitHub
parent 1c6e5f0f20
commit ea9f2f81f1
3 changed files with 223 additions and 185 deletions

View File

@ -1698,13 +1698,22 @@ function loadStockTable(table, options) {
sortable: true,
formatter: function(value, row) {
var val = parseFloat(value);
var val = '';
var available = Math.max(0, (row.quantity || 0) - (row.allocated || 0));
// If there is a single unit with a serial number, use the serial number
if (row.serial && row.quantity == 1) {
// If there is a single unit with a serial number, use the serial number
val = '# ' + row.serial;
} else if (row.quantity != available) {
// Some quantity is available, show available *and* quantity
var ava = +parseFloat(available).toFixed(5);
var tot = +parseFloat(row.quantity).toFixed(5);
val = `${ava} / ${tot}`;
} else {
val = +val.toFixed(5);
// Format floating point numbers with this one weird trick
val = +parseFloat(value).toFixed(5);
}
var html = renderLink(val, `/stock/item/${row.pk}/`);
@ -1719,16 +1728,7 @@ function loadStockTable(table, options) {
} else if (row.customer) {
// StockItem has been assigned to a customer
html += makeIconBadge('fa-user', '{% trans "Stock item assigned to customer" %}');
}
if (row.expired) {
html += makeIconBadge('fa-calendar-times icon-red', '{% trans "Stock item has expired" %}');
} else if (row.stale) {
html += makeIconBadge('fa-stopwatch', '{% trans "Stock item will expire soon" %}');
}
if (row.allocated) {
} else if (row.allocated) {
if (row.serial != null && row.quantity == 1) {
html += makeIconBadge('fa-bookmark icon-yellow', '{% trans "Serialized stock item has been allocated" %}');
} else if (row.allocated >= row.quantity) {
@ -1736,10 +1736,14 @@ function loadStockTable(table, options) {
} else {
html += makeIconBadge('fa-bookmark', '{% trans "Stock item has been partially allocated" %}');
}
} else if (row.belongs_to) {
html += makeIconBadge('fa-box', '{% trans "Stock item has been installed in another item" %}');
}
if (row.belongs_to) {
html += makeIconBadge('fa-box', '{% trans "Stock item has been installed in another item" %}');
if (row.expired) {
html += makeIconBadge('fa-calendar-times icon-red', '{% trans "Stock item has expired" %}');
} else if (row.stale) {
html += makeIconBadge('fa-stopwatch', '{% trans "Stock item will expire soon" %}');
}
// Special stock status codes