Update stock table rendering

This commit is contained in:
Oliver Walters 2020-04-20 01:02:19 +10:00
parent 6a89e0089d
commit 4b1b9df193

View File

@ -45,6 +45,9 @@ function loadStockTable(table, options) {
*/ */
// List of user-params which override the default filters // List of user-params which override the default filters
options.params['part_detail'] = true;
var params = options.params || {}; var params = options.params || {};
var filterListElement = options.filterList || "#filter-list-stock"; var filterListElement = options.filterList || "#filter-list-stock";
@ -83,27 +86,21 @@ function loadStockTable(table, options) {
var row = data[0]; var row = data[0];
if (field == 'part__name') { if (field == 'part_name') {
var name = row.part__IPN; var name = row.part_detail.full_name;
if (name) { return imageHoverIcon(row.part_detail.thumbnail) + name + ' <i>(' + data.length + ' items)</i>';
name += ' | ';
} }
else if (field == 'part_description') {
name += row.part__name; return row.part_detail.description;
return imageHoverIcon(row.part__thumbnail) + name + ' <i>(' + data.length + ' items)</i>';
}
else if (field == 'part__description') {
return row.part__description;
} }
else if (field == 'quantity') { else if (field == 'quantity') {
var stock = 0; var stock = 0;
var items = 0; var items = 0;
data.forEach(function(item) { data.forEach(function(item) {
stock += item.quantity; stock += parseFloat(item.quantity);
items += 1; items += 1;
}); });
@ -216,25 +213,14 @@ function loadStockTable(table, options) {
visible: false, visible: false,
}, },
{ {
field: 'part__name', field: 'part_name',
title: 'Part', title: 'Part',
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {
var name = row.part__IPN;
if (name) {
name += ' | ';
}
name += row.part__name;
if (row.part__revision) {
name += " | ";
name += row.part__revision;
}
var url = ''; var url = '';
var thumb = row.part_detail.thumbnail;
var name = row.part_detail.full_name;
if (row.supplier_part) { if (row.supplier_part) {
url = `/supplier-part/${row.supplier_part}/`; url = `/supplier-part/${row.supplier_part}/`;
@ -242,13 +228,16 @@ function loadStockTable(table, options) {
url = `/part/${row.part}/`; url = `/part/${row.part}/`;
} }
return imageHoverIcon(row.part__thumbnail) + renderLink(name, url); return imageHoverIcon(thumb) + renderLink(name, url);
} }
}, },
{ {
field: 'part__description', field: 'part_description',
title: 'Description', title: 'Description',
sortable: true, sortable: true,
formatter: function(value, row, index, field) {
return row.part_detail.description;
}
}, },
{ {
field: 'quantity', field: 'quantity',
@ -256,11 +245,13 @@ function loadStockTable(table, options) {
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {
var val = value; var val = parseFloat(value);
// If there is a single unit with a serial number, use the serial number // If there is a single unit with a serial number, use the serial number
if (row.serial && row.quantity == 1) { if (row.serial && row.quantity == 1) {
val = '# ' + row.serial; val = '# ' + row.serial;
} else {
val = +val.toFixed(5);
} }
var text = renderLink(val, '/stock/item/' + row.pk + '/'); var text = renderLink(val, '/stock/item/' + row.pk + '/');
@ -282,7 +273,7 @@ function loadStockTable(table, options) {
sortable: true, sortable: true,
}, },
{ {
field: 'location__path', field: 'location_detail.pathstring',
title: 'Location', title: 'Location',
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {