Repository navigation
fix(billing): [OM-434] delete empty invoices during issuing - #4849
Conversation
📝 WalkthroughWalkthroughInvoices with no non-deleted lines now enter system deletion instead of issuance. The change updates state handling, sandbox call tracking, documentation, and standard and custom-currency lifecycle tests. Active zero-total invoices still follow the issuing path. ChangesEmpty invoice deletion
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Approval
participant InvoiceState
participant SandboxApp
Approval->>InvoiceState: Approve draft invoice
InvoiceState->>InvoiceState: Check for non-deleted lines
InvoiceState->>InvoiceState: Prepare system deletion
InvoiceState->>SandboxApp: Synchronize invoice deletion
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
test/billing/invoice_test.go (1)
1547-1547: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
Require().Equalfor the zero-total precondition.Replace
s.Zero(...)withs.Require().Equal(float64(0), ...). This keeps the decimal assertion in the required form and stops the lifecycle test when its setup is invalid.Proposed change
- s.Zero(invoice.Totals.Total.InexactFloat64()) + s.Require().Equal(float64(0), invoice.Totals.Total.InexactFloat64())As per coding guidelines, “When precision permits, compare
alpacadecimal.DecimalthroughInexactFloat64()withrequire.Equal; inline one-off expected balances.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/billing/invoice_test.go` at line 1547, Replace the s.Zero() assertion on invoice.Totals.Total.InexactFloat64() with s.Require().Equal(float64(0), invoice.Totals.Total.InexactFloat64()) to use the required form for the precondition check. This ensures the test lifecycle stops when its setup is invalid and aligns with the coding guideline for comparing decimal values through InexactFloat64() with require.Equal.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@openmeter/billing/README.md`:
- Around line 96-97: In the documentation describing the invoice lifecycle
condition, replace the term "visible line" with "non-deleted line" to accurately
reflect the actual criterion used. A deleted line can be visible when
deleted-line expansion is requested, so the decision criterion is whether a line
is non-deleted, not whether it appears visually. Update the sentence to state
that a non-deleted line with a zero total follows the normal issuing lifecycle,
while maintaining the explanation about deleted lines entering deletion.
In `@openmeter/billing/service/stdinvoicestate.go`:
- Around line 904-906: The TODO comment around line 46 states that invoice
deletion is not implemented, but the diff now shows that deleteInvoice is being
called to prepare a system deletion for empty invoices, making this TODO stale.
Either remove the TODO entirely if invoice deletion is now fully supported, or
update it to only document specific deletion behaviors that remain unsupported,
excluding the empty invoice deletion scenario that is now prepared via the
deleteInvoice call with ChangeSourceSystem.
---
Nitpick comments:
In `@test/billing/invoice_test.go`:
- Line 1547: Replace the s.Zero() assertion on
invoice.Totals.Total.InexactFloat64() with s.Require().Equal(float64(0),
invoice.Totals.Total.InexactFloat64()) to use the required form for the
precondition check. This ensures the test lifecycle stops when its setup is
invalid and aligns with the coding guideline for comparing decimal values
through InexactFloat64() with require.Equal.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 5bdd9006-11a9-4178-9e35-86ade37d1e7b
📒 Files selected for processing (6)
openmeter/app/sandbox/mock.goopenmeter/billing/README.mdopenmeter/billing/charges/service/invoicable_test.goopenmeter/billing/charges/service/usagebased_test.goopenmeter/billing/service/stdinvoicestate.gotest/billing/invoice_test.go
4824648 to
2359e94
Compare
2e58a58 to
ad95170
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Summary
When issuing begins, billing now deletes a standard invoice if it has no non-deleted lines. The deletion is recorded as a system change and synchronized to the configured invoicing app instead of finalizing the invoice.
This is stacked on #4843, where custom-currency overage lines can be deleted after credits fully cover the charge or the resulting fiat amount rounds to zero. Those invoices now complete their lifecycle as deleted rather than remaining as empty drafts.
Behavioral changes
delete.failedand can be retried without replacing the original deletion timestamp.deletedas the approval result when the expanded invoice is empty.Validation
make lint-go-fastin the repository's Nix development shell.Jira: OM-434
Summary by CodeRabbit
Greptile Summary
This PR routes standard invoices with no active lines through the existing deletion lifecycle when issuing begins, preserving normal issuing for zero-total invoices that still contain an active line.
draft.ready_to_issue.Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD Ready["draft.ready_to_issue"] --> Check{"Any non-deleted lines?"} Check -->|Yes| SyncIssue["issuing.syncing"] SyncIssue --> Finalize["Finalize through invoicing app"] Check -->|No| Prepare["Prepare system deletion"] Prepare --> SyncDelete["delete.syncing"] SyncDelete --> AppDelete["Delete through invoicing app"] AppDelete -->|Success| Deleted["deleted"] AppDelete -->|Failure| DeleteFailed["delete.failed"] DeleteFailed -->|Retry| SyncDeleteReviews (3): Last reviewed commit: "chore(billing): address invoice deletion..." | Re-trigger Greptile
Context used: