-
Notifications
You must be signed in to change notification settings - Fork 152
fix: updating gathering invoices with split lines #2918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughThe update modifies the invoice update logic to clear the Changes
Possibly related PRs
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (12)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
openmeter/billing/service/invoice.go (1)
904-917: Good fix for preventing cross-invoice operations, but consider avoiding direct object mutation.The implementation correctly addresses the PR objective by clearing children from split lines to prevent unsupported cross-invoice operations. The logic is sound and well-documented.
However, directly mutating the line object (
line.Children = billing.LineChildren{}) could cause issues if the line is referenced elsewhere. Consider creating a copy of the line before modification.Apply this diff to avoid direct mutation:
-invoice.Lines = billing.NewLineChildren(lo.Map(invoice.Lines.OrEmpty(), func(line *billing.Line, _ int) *billing.Line { - if line.Status != billing.InvoiceLineStatusSplit { - return line - } - - // This makes the line children not present in the invoice - line.Children = billing.LineChildren{} - - return line -})) +invoice.Lines = billing.NewLineChildren(lo.Map(invoice.Lines.OrEmpty(), func(line *billing.Line, _ int) *billing.Line { + if line.Status != billing.InvoiceLineStatusSplit { + return line + } + + // Create a copy to avoid mutating the original line + lineCopy := *line + // This makes the line children not present in the invoice + lineCopy.Children = billing.LineChildren{} + + return &lineCopy +}))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
openmeter/billing/service/invoice.go(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
- GitHub Check: Commit hooks
- GitHub Check: Quickstart
- GitHub Check: CI
- GitHub Check: Lint
- GitHub Check: E2E
- GitHub Check: Developer environment
- GitHub Check: Test
- GitHub Check: Migration Checks
- GitHub Check: Build
- GitHub Check: Analyze (go)
This patch makes sure that for gathering invoices we are not returning the split line's children as that would cause a cross invoice operation that is not supported by the system (as both invoices would need to be recalculated).
da79f7e to
20239e7
Compare
Overview
This patch makes sure that for gathering invoices we are not returning the split line's children as that would cause a cross invoice operation that is not supported by the system (as both invoices would need to be recalculated).
Summary by CodeRabbit