You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(billing): load split-line history as persisted facts - #5333
Split-line history reads expand full line and invoice aggregates even though legacy rating and subscription sync need only persisted history facts. Load those facts directly while preserving deleted children, previously billed amounts, ownership, scheduling, and reconciliation behavior.
Notes for reviewer
Follows #5326. Ordinary header-only rating and the full-line transports used elsewhere remain intact. Subscription-reference billing periods retain their stored precision; service-period and gathering InvoiceAt normalization remain.
Validated the affected unit tests and targeted PostgreSQL billing and subscription-sync scenarios, plus go vet and scoped fast lint.
Summary by CodeRabbit
Bug Fixes
Improved billing history and reconciliation for split-line hierarchies.
Deleted child lines remain available for reconciliation, while previously billed amounts exclude deleted lines and invoices.
Corrected handling of terminal deleted invoices without deletion timestamps.
Improved subscription synchronization for hierarchy changes, ownership, annotations, and billing periods.
Tests
Expanded coverage for hierarchy cloning, reconciliation, deletion handling, and discount tracking.
Confidence Score: 5/5
The PR appears safe to merge; no actionable new issue was found.
Summary
The PR loads split-line history as persisted facts instead of full line and invoice aggregates.
Billing rating and subscription sync now read stored split-line facts.
Subscription sync uses saved child history to reconcile split-line groups.
The latest change maps subscription billing-period endpoints independently. No actionable new issue was found. No previous review threads were supplied.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
DB["Stored split-line groups and children"] --> Adapter["Load persisted history facts"]
Adapter --> Hierarchy["SplitLineHierarchy"]
Hierarchy --> Rating["Sum previously billed amounts"]
Hierarchy --> Sync["Build subscription reconciliation patches"]
Sync --> Updater["Load canonical lines and apply patches"]
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
📝 Walkthrough
Split-line hierarchies now store persisted invoice and line facts directly. Billing calculations, subscription-state loading, and reconciliation use those fields. Tests cover amount calculations, cloning, persisted-state selection, and hierarchy patch behavior.
Changes: Split-line history and reconciliation
Layer / File(s)
Summary
Persisted hierarchy model and mapping openmeter/billing/invoicelinesplitgroup.go, openmeter/billing/adapter/invoicelinesplitgroup.go, openmeter/billing/service/invoicelinesplitgroup.go, openmeter/billing/README.md, openmeter/billing/*_test.go, openmeter/billing/lineengine/rating_test.go, test/billing/*_test.go
The hierarchy stores invoice and line fields directly. The adapter maps expanded invoices to this structure. Amount calculations, child traversal, cloning, and billing callers use persisted values.
Persisted state loading and selection openmeter/billing/worker/subscriptionsync/service/persistedstate/*
Loading and normalization operate on hierarchy-line fields. Ownership and annotation selection use the first undeleted child. Tests cover normalization and selection order.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kind/refactorCode refactor, cleanup or minor improvement
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Split-line history reads expand full line and invoice aggregates even though legacy rating and subscription sync need only persisted history facts. Load those facts directly while preserving deleted children, previously billed amounts, ownership, scheduling, and reconciliation behavior.
Notes for reviewer
Follows #5326. Ordinary header-only rating and the full-line transports used elsewhere remain intact. Subscription-reference billing periods retain their stored precision; service-period and gathering
InvoiceAtnormalization remain.Validated the affected unit tests and targeted PostgreSQL billing and subscription-sync scenarios, plus
go vetand scoped fast lint.Summary by CodeRabbit
Bug Fixes
Tests


Confidence Score: 5/5
The PR appears safe to merge; no actionable new issue was found.Summary
The PR loads split-line history as persisted facts instead of full line and invoice aggregates.
The latest change maps subscription billing-period endpoints independently. No actionable new issue was found. No previous review threads were supplied.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR DB["Stored split-line groups and children"] --> Adapter["Load persisted history facts"] Adapter --> Hierarchy["SplitLineHierarchy"] Hierarchy --> Rating["Sum previously billed amounts"] Hierarchy --> Sync["Build subscription reconciliation patches"] Sync --> Updater["Load canonical lines and apply patches"]Reviews (2) · Last reviewed commit: "refactor(billing): map split-line subscr..." · Reviewed by Greptile