Skip to content

Commit

Permalink
fix: streamline cashback removal process to eliminate empty entries f…
Browse files Browse the repository at this point in the history
…rom breakdown
  • Loading branch information
JoFont committed Dec 7, 2024
1 parent 79f0eab commit 46ee387
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,6 @@ const recomputeDetailTotals = (
const matchingCashback = cashbacks[cashbackMatchIndex];
const cashbackAmountTotal = toDineroFromInteger(matchingCashback.amount_total);
matchingCashback.amount_total = cashbackAmountTotal.add(priceCashBackAmount).getAmount();

// Removes cashback if the total amount is 0, this is to avoid having empty cashbacks in the breakdown
// TODO: Improve this so that the metadata is not carrying around keys that no longer apply, like a coupon with a 0 amount
if (matchingCashback.amount_total === 0) {
cashbacks.splice(cashbackMatchIndex, 1);
}
} else {
cashbacks.push({
cashback_period: cashbackPeriod,
Expand All @@ -600,6 +594,11 @@ const recomputeDetailTotals = (
}
}

// Remove empty cashbacks from the breakdown
if (cashbacks.length > 0) {
cashbacks.filter((cashback) => cashback.amount_total > 0);
}

return {
amount_subtotal: subtotal.add(priceSubtotal).getAmount(),
amount_total: total.add(priceTotal).getAmount(),
Expand Down

0 comments on commit 46ee387

Please sign in to comment.