Repository navigation
fix(billing): stamp manual invoice edits in service diff - #4591
Conversation
|
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)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR changes invoice-line edit ownership stamping, legacy override validation, and lifecycle-controller mapping for flat-fee manual overrides. It also updates related helpers, tests, and billing guidance, plus one e2e flow covering invoice replacement and charge ownership. ChangesFlat-fee manual override edit flow
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
Greptile SummaryThis PR updates manual invoice-line edit handling in billing. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (2): Last reviewed commit: "test(e2e): tighten charge override asser..." | Re-trigger Greptile |
| } | ||
| req.StatusIn = statuses | ||
| // TODO: Also add a deleted_at filter | ||
| req.IncludeDeleted = slices.Contains(statuses, meta.ChargeStatusDeleted) |
There was a problem hiding this comment.
Deleted Rows Broaden Mixed Filters
When filter[status][oeq] contains both active and deleted, this flips IncludeDeleted for the whole repository query. That removes the normal deleted_at IS NULL guard for the active branch too, so soft-deleted override rows whose status is still active can be returned as active charges.
Prompt To Fix With AI
This is a comment left during a code review.
Path: api/v3/handlers/customers/charges/list.go
Line: 110
Comment:
**Deleted Rows Broaden Mixed Filters**
When `filter[status][oeq]` contains both `active` and `deleted`, this flips `IncludeDeleted` for the whole repository query. That removes the normal `deleted_at IS NULL` guard for the active branch too, so soft-deleted override rows whose status is still active can be returned as active charges.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@e2e/billinginvoice_override_test.go`:
- Around line 670-675: The helper comment on
assertFlatFeeChargeLifecycleController is stale and misleading because the
lifecycle contract now treats LifecycleController as manual whenever an override
layer exists, regardless of the underlying subscription-managed sync behavior.
Update the comment to describe the observable override/controller behavior
instead of tying it to invoice-line ManagedBy ownership, keeping the wording
aligned with the helper’s assertions in assertFlatFeeChargeLifecycleController
and the flatFee LifecycleController field.
- Around line 643-668: `listChargesByName` currently overwrites entries when two
charges have the same name, so add a uniqueness check before writing into the
map. In the helper that switches on `charge.Discriminator()` and builds `out`,
assert that the derived key (`flatFee.Name` or `usageBased.Name`) is not already
present and fail the test immediately if it is. This should be done inside
`listChargesByName` so the e2e catches duplicate charge emission instead of
silently passing.
🪄 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
Run ID: 1fea0538-6cee-44a2-b95e-ace064388170
📒 Files selected for processing (17)
.agents/skills/billing/SKILL.md.agents/skills/charges/SKILL.mdapi/v3/handlers/customers/charges/convert.goapi/v3/handlers/customers/charges/list.goe2e/billinginvoice_override_test.goe2e/v3helpers_test.goopenmeter/billing/httpdriver/invoiceline.goopenmeter/billing/httpdriver/invoiceline_test.goopenmeter/billing/invoiceline.goopenmeter/billing/lineengine/engine.goopenmeter/billing/lineengine/engine_test.goopenmeter/billing/service/gatheringinvoice.goopenmeter/billing/service/invoiceupdate.goopenmeter/billing/service/invoiceupdate_test.goopenmeter/billing/service/lineengine_test.goopenmeter/billing/service/stdinvoice.goopenmeter/billing/worker/subscriptionsync/service/sync_credittheninvoice_test.go
Summary
Root Cause
API-created charge-backed invoice lines could reach line engines with caller-supplied ownership because ownership stamping had drifted into the apply path. The credit-then-invoice update tests also masked part of the behavior by setting
ManagedByinside the API edit closure.Validation
direnv exec . make lint-go-fastdirenv exec . make test-nocacheSummary by CodeRabbit