Purchase history graph fix (#5421)

* Fix debug messages

* Fix bug in purchase history chart

- Use new pack_quantity_native attribute
This commit is contained in:
Oliver 2023-08-10 14:24:59 +10:00 committed by GitHub
parent a1d2782137
commit 86ca0b27a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -292,7 +292,7 @@ function loadBomPricingChart(options={}) {
var part = options.part;
if (!part) {
console.error('No part provided to loadPurchasePriceHistoryTable');
console.error('No part provided to loadBomPricingChart');
return;
}
@ -434,7 +434,7 @@ function loadPartSupplierPricingTable(options={}) {
var part = options.part;
if (!part) {
console.error('No part provided to loadPurchasePriceHistoryTable');
console.error('No part provided to loadPartSupplierPricingTable');
return;
}
@ -764,7 +764,21 @@ function loadPurchasePriceHistoryTable(options={}) {
data = data.sort((a, b) => (a.order_detail.complete_date - b.order_detail.complete_date));
var graphLabels = Array.from(data, (x) => (`${x.order_detail.reference} - ${x.order_detail.complete_date}`));
var graphValues = Array.from(data, (x) => (x.purchase_price / x.supplier_part_detail.pack_size));
var graphValues = Array.from(data, (x) => {
let pp = x.purchase_price;
let div = 1.0;
if (x.supplier_part_detail) {
div = parseFloat(x.supplier_part_detail.pack_quantity_native);
if (isNaN(div) || !isFinite(div)) {
div = 1.0;
}
}
return pp / div;
});
if (chart) {
chart.destroy();