Skip to content

Fix after_cashback_amount_total to use the line total#287

Open
josecarneiro wants to merge 1 commit into
mainfrom
fix/after-cashback-amount-total-line-total
Open

Fix after_cashback_amount_total to use the line total#287
josecarneiro wants to merge 1 commit into
mainfrom
fix/after-cashback-amount-total-line-total

Conversation

@josecarneiro

Copy link
Copy Markdown
Contributor

In applyDiscounts, the cashback branch computed after_cashback_amount_total from the per-unit gross amount instead of the line total:

afterCashbackAmountTotal = unitAmountGross.subtract(normalizedCashbackAmount);

When the quantity multiplier is 1, unit_amount_gross === amount_total, so the result was correct by coincidence. But when the unit amount is multiplied by a quantity/consumption (so amount_total = unit_amount_gross × multiplier), subtracting the full cashback from the small per-unit figure produced wrong — often negative — totals. This also left the item-level value inconsistent with the recurrence-level after_cashback_amount_total, which was already derived from the total.

Fix

Deduct the cashback from amount_total. Item-level and recurrence-level values now reconcile (the item afters sum to the recurrence after).

  • apply-discounts.ts — use amount_total as the base.
  • pricing.results.ts — corrected a fixture that encoded the old value (8000 → 18000; amount_total 20000 − cashback 2000).
  • pricing-getag.test.ts — added regression coverage for the multiplier-≠-1 cashback case, plus a withCouponOnComponents helper.

Only after_cashback_amount_total changes, and only when the multiplier ≠ 1; it's a leaf output, so aggregates are unaffected.

@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: caa0c96

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant