From 86ca0b27a42a1dc2dea8034444ea1b30d1fd9ca0 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 10 Aug 2023 14:24:59 +1000 Subject: [PATCH] Purchase history graph fix (#5421) * Fix debug messages * Fix bug in purchase history chart - Use new pack_quantity_native attribute --- InvenTree/templates/js/translated/pricing.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/InvenTree/templates/js/translated/pricing.js b/InvenTree/templates/js/translated/pricing.js index 3d6db729d9..7b2c8eee63 100644 --- a/InvenTree/templates/js/translated/pricing.js +++ b/InvenTree/templates/js/translated/pricing.js @@ -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();