fix: regression in gathering invoice rendering#3939
Conversation
When a progressively billed line is present on a gathering invoice the rendered standard invoice failed to show the correct value.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a new Changes
Sequence Diagram(s)sequenceDiagram
participant InvoiceService as Invoice Service
participant Adapter as GatheringInvoice Adapter (DB)
participant Model as Billing Models
participant Mapper as AsNewStandardLine
InvoiceService->>Adapter: fetch gathering invoice (may request SplitLineHierarchy expand)
Adapter-->>Model: mapGatheringInvoiceFromDB (populate Expands)
InvoiceService->>Model: check lines & Expands
alt needs reload for SplitLineHierarchy/progressive lines
InvoiceService->>Adapter: refetch with SplitLineHierarchy expanded
Adapter-->>Model: mapGatheringInvoiceFromDB (Expands includes SplitLineHierarchy)
end
Model->>Mapper: for each GatheringLine, AsNewStandardLine (clone SplitLineHierarchy)
Mapper-->>Model: return StandardLine with wired SplitLineHierarchy
InvoiceService-->>Model: emit StandardInvoice
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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 Tip You can disable the changed files summary in the walkthrough.Disable the |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
openmeter/billing/service/invoice.go (1)
169-202: Logic looks solid, with one tiny nit.The reload detection logic correctly identifies when we need to fetch the split line hierarchy for progressive billing calculations. Good pattern of capturing
wasLinesPresentupfront before any potential reload.Minor redundancy: On lines 196-197,
GatheringInvoiceExpandAllalready includesGatheringInvoiceExpandSplitLineHierarchy(defined ingatheringinvoice.goline 208), so the.With(...)is a no-op. Not harmful sinceWith()handles duplicates gracefully, but could be simplified.✨ Optional simplification
invoice, err = s.adapter.GetGatheringInvoiceById(ctx, billing.GetGatheringInvoiceByIdInput{ Invoice: in.Invoice.GetInvoiceID(), - Expand: billing.GatheringInvoiceExpandAll. - With(billing.GatheringInvoiceExpandSplitLineHierarchy), + Expand: billing.GatheringInvoiceExpandAll, })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/billing/service/invoice.go` around lines 169 - 202, Remove the redundant explicit With(...) call when reloading the invoice: simplify the reload call that currently uses billing.GatheringInvoiceExpandAll.With(billing.GatheringInvoiceExpandSplitLineHierarchy) to just use billing.GatheringInvoiceExpandAll because GatheringInvoiceExpandAll already includes GatheringInvoiceExpandSplitLineHierarchy; update the call site in the GetGatheringInvoiceById invocation (referenced as s.adapter.GetGatheringInvoiceById and the variables invoice and shouldReloadLines) to pass billing.GatheringInvoiceExpandAll directly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@openmeter/billing/service/invoice.go`:
- Around line 169-202: Remove the redundant explicit With(...) call when
reloading the invoice: simplify the reload call that currently uses
billing.GatheringInvoiceExpandAll.With(billing.GatheringInvoiceExpandSplitLineHierarchy)
to just use billing.GatheringInvoiceExpandAll because GatheringInvoiceExpandAll
already includes GatheringInvoiceExpandSplitLineHierarchy; update the call site
in the GetGatheringInvoiceById invocation (referenced as
s.adapter.GetGatheringInvoiceById and the variables invoice and
shouldReloadLines) to pass billing.GatheringInvoiceExpandAll directly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 98370567-2f3b-470f-918e-97be449c8d78
📒 Files selected for processing (3)
openmeter/billing/adapter/gatheringinvoice.goopenmeter/billing/gatheringinvoice.goopenmeter/billing/service/invoice.go
Overview
When a progressively billed line is present on a gathering invoice the rendered standard invoice failed to show the correct value.
Summary by CodeRabbit