Skip to content

Commit

Permalink
Purchase history graph fix (#5421)
Browse files Browse the repository at this point in the history
* Fix debug messages

* Fix bug in purchase history chart

- Use new pack_quantity_native attribute
  • Loading branch information
SchrodingersGat authored Aug 10, 2023
1 parent a1d2782 commit 86ca0b2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions InvenTree/templates/js/translated/pricing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 86ca0b2

Please sign in to comment.