Repository navigation
fix(billing): net prior split discounts in legacy commitment history - #5367
Conversation
…t; focused test 100 vs 60 red before, green after; billing tests and vet pass
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Preserve discounts in history openmeter/billing/invoicelinesplitgroup.go, openmeter/billing/adapter/invoicelinesplitgroup.go |
SplitLineHierarchyLine adds DiscountsTotal. The database mapping copies this value into the hierarchy line. |
Subtract discounts from prior net amounts openmeter/billing/invoicelinesplitgroup.go, openmeter/billing/splitlinehierarchy_test.go, test/billing/discount_test.go, test/credits_billing_compat/discount_test.go, openmeter/billing/README.md |
SumNetAmount subtracts discounts from eligible child amounts and still adds charges when requested. Tests cover discounted totals and progressive minimum and maximum spend commitments. The README describes how discounts and commitment amounts are counted across slices. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Possibly related PRs
- openmeterio/openmeter#5333: Introduced the persisted split-line history model and traversal used by
SumNetAmount. - openmeterio/openmeter#5356: Changed legacy calculations to resolve persisted split-line history.
- openmeterio/openmeter#5341: Routed prior-spend calculations through
SplitLineHierarchy.SumNetAmount.
Suggested reviewers: turip, borosr
Merge Risk: 
Minimal · up to 5f13c
-
The change appears mergeable after normal checks; the database-backed invoice flows have not been independently run.
Pre-merge checks: 
4
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Problem
SplitLineHierarchy.SumNetAmountsums persisted prior-lineAmount, which is gross, while the caller treats it as net spend when evaluating commitments. The split-line history introduced in #5341 carries gross amount and charges but omitsDiscountsTotal, even though the persisted invoice line has that field. A prior line with 100 in gross amount and 40 in discounts therefore contributes 100 where the function promises 60.This carries
DiscountsTotalinto the history model and subtracts it inSumNetAmount. #5297 established the net-of-discounts calculation for the separate delta engine; this change addresses the legacy history path.Verification
DiscountsTotal, andSumNetAmountreturns 60. Passed.go test ./openmeter/billing/...passed.go vet ./openmeter/billing/... ./test/...passed.This demonstrates the history sum and adapter mapping. I did not run a database-backed invoice flow or independently execute the maximum-spend commitment path.
Summary by CodeRabbit


Confidence Score: 5/5
The PR appears safe to merge; no actionable issue remains.Summary
The PR makes legacy commitment history count prior spend after discounts.
No new actionable issues or repository-rule violations were found. Tests were not run during this review.
Reviews (5) · Last reviewed commit: "test(billing): mirror progressive commit..." · Reviewed by Greptile