Repository navigation
refactor(billing): remove detailed line tax config domain - #4460
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 ignored due to path filters (6)
📒 Files selected for processing (17)
💤 Files with no reviewable changes (8)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (8)
📝 WalkthroughWalkthroughRemoves detailed-line TaxConfig from models and persistence, adds per-leaf resolved TaxConfig on invoices, and threads that resolved config through API mapping, Stripe invoice builders, adapters, and tests. ChangesTax Config Resolution and Model Refactoring
Sequence Diagram(s)sequenceDiagram
participant StandardInvoice
participant LeafResolver
participant StripeBuilder
participant APIMapper
StandardInvoice->>LeafResolver: GetLeafLinesWithResolvedTaxConfig()
LeafResolver-->>StandardInvoice: []DetailedLineWithResolvedTaxConfig
StandardInvoice->>StripeBuilder: build invoice items (line, discount, credit) with resolved taxConfig
StripeBuilder->>StripeBuilder: applyTaxSettingsToInvoiceItem(taxConfig)
StandardInvoice->>APIMapper: mapDetailedLinesToAPI(taxConfig)
APIMapper-->>StandardInvoice: API invoice lines with tax fields
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
554f3aa to
c3e2794
Compare
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
openmeter/billing/charges/flatfee/adapter/detailedline.go (1)
40-48:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winDrop the now-unused
WithTaxCode()eager-load inFetchCurrentRunDetailedLines.
openmeter/billing/charges/flatfee/adapter/detailedline.gohas no otherTaxCodeusage besides the.WithTaxCode()call on the query, so this edge is only being loaded unnecessarily (extra eager-load query on the read path).♻️ Proposed cleanup
dbLines, err := tx.db.ChargeFlatFeeRunDetailedLine.Query(). Where( dbchargeflatfeerundetailedline.NamespaceEQ(charge.Namespace), dbchargeflatfeerundetailedline.RunIDEQ(currentRunID.ID), dbchargeflatfeerundetailedline.DeletedAtIsNil(), ). - WithTaxCode(). All(ctx)🤖 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 `@openmeter/billing/charges/flatfee/adapter/detailedline.go` around lines 40 - 48, The query in FetchCurrentRunDetailedLines is performing an unnecessary eager-load by calling WithTaxCode(); remove the WithTaxCode() invocation from the DB query that produces dbLines so the TaxCode edge is not fetched, then ensure the loop that converts dbLines to flatfee.DetailedLines via stddetailedline.FromDB remains unchanged (no other TaxCode usages exist).
🧹 Nitpick comments (2)
test/app/stripe/invoice_test.go (1)
565-566: ⚡ Quick winAdd one assertion for resolved tax config in this flow.
This helper now walks
GetLeafLinesWithResolvedTaxConfig(), but the test still never checks that inherited/default tax config actually shows up in the Stripe params. A small case with invoice default tax config plus a parent-line override would lock down the core behavior of this refactor.As per coding guidelines, "
**/*_test.go: Make sure the tests are comprehensive and cover the changes."openmeter/billing/charges/usagebased/adapter/detailedline.go (1)
40-40: ⚡ Quick winDrop the dead
.WithTaxCode()eager load inFetchDetailedLines
mapDetailedLineFromDB+usagebased.DetailedLine.Validate()don’t use any tax-code/tax-config data (they only consumestddetailedline.FromDB(dbLine)plusPricerReferenceID/CorrectsRunID), so thisWithTaxCode()join/load is orphaned on this path.♻️ Proposed cleanup
dbLines, err := tx.db.ChargeUsageBasedRunDetailedLine.Query(). Where( dbchargeusagebasedrundetailedline.NamespaceEQ(charge.Namespace), dbchargeusagebasedrundetailedline.ChargeIDEQ(charge.ID), dbchargeusagebasedrundetailedline.RunIDIn(runIDs...), dbchargeusagebasedrundetailedline.DeletedAtIsNil(), ). - WithTaxCode(). All(ctx)🤖 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 `@openmeter/billing/charges/usagebased/adapter/detailedline.go` at line 40, The eager-load call WithTaxCode() in FetchDetailedLines is dead — mapDetailedLineFromDB and usagebased.DetailedLine.Validate() do not use tax-code/tax-config data — so remove the WithTaxCode() invocation from the query construction in FetchDetailedLines; ensure FetchDetailedLines still returns the expected fields (stddetailedline.FromDB(dbLine), PricerReferenceID, CorrectsRunID) and run/update any tests that assumed the tax join was present.
🤖 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/httpdriver/invoiceline.go`:
- Line 327: The call to mapDetailedLinesToAPI currently passes the raw
line.TaxConfig which ignores inherited defaults; compute the effective/merged
tax config (e.g., merge line.TaxConfig with
invoice.Workflow.Config.Invoicing.DefaultTaxConfig or use the already-resolved
tax config used for the parent line) and pass that merged config into
mapDetailedLinesToAPI in place of line.TaxConfig so child detailed-line mapping
uses the resolved tax settings consistent with the invoice.
---
Outside diff comments:
In `@openmeter/billing/charges/flatfee/adapter/detailedline.go`:
- Around line 40-48: The query in FetchCurrentRunDetailedLines is performing an
unnecessary eager-load by calling WithTaxCode(); remove the WithTaxCode()
invocation from the DB query that produces dbLines so the TaxCode edge is not
fetched, then ensure the loop that converts dbLines to flatfee.DetailedLines via
stddetailedline.FromDB remains unchanged (no other TaxCode usages exist).
---
Nitpick comments:
In `@openmeter/billing/charges/usagebased/adapter/detailedline.go`:
- Line 40: The eager-load call WithTaxCode() in FetchDetailedLines is dead —
mapDetailedLineFromDB and usagebased.DetailedLine.Validate() do not use
tax-code/tax-config data — so remove the WithTaxCode() invocation from the query
construction in FetchDetailedLines; ensure FetchDetailedLines still returns the
expected fields (stddetailedline.FromDB(dbLine), PricerReferenceID,
CorrectsRunID) and run/update any tests that assumed the tax join was present.
🪄 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: bc521a00-1f3b-40ac-a4e9-a448cffd675a
⛔ Files ignored due to path filters (6)
openmeter/ent/db/billingstandardinvoicedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline/billingstandardinvoicedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeerundetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeerundetailedline/chargeflatfeerundetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedrundetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedrundetailedline/chargeusagebasedrundetailedline.gois excluded by!**/ent/db/**
📒 Files selected for processing (17)
openmeter/app/stripe/appinvoice.goopenmeter/billing/adapter/stdinvoicelinemapper.goopenmeter/billing/adapter/stdinvoicelines.goopenmeter/billing/charges/flatfee/adapter/detailedline.goopenmeter/billing/charges/flatfee/adapter/mapper.goopenmeter/billing/charges/usagebased/adapter/detailedline.goopenmeter/billing/charges/usagebased/detailedline.goopenmeter/billing/charges/usagebased/service/rating/service_test.goopenmeter/billing/httpdriver/invoiceline.goopenmeter/billing/models/stddetailedline/derived.gen.goopenmeter/billing/models/stddetailedline/mapping.goopenmeter/billing/models/stddetailedline/mixin.goopenmeter/billing/models/stddetailedline/model.goopenmeter/billing/service/invoicecalc/details.goopenmeter/billing/stdinvoice.gotest/app/stripe/invoice_test.gotest/billing/tax_test.go
💤 Files with no reviewable changes (8)
- openmeter/billing/charges/usagebased/service/rating/service_test.go
- openmeter/billing/charges/flatfee/adapter/mapper.go
- openmeter/billing/models/stddetailedline/derived.gen.go
- openmeter/billing/models/stddetailedline/model.go
- openmeter/billing/charges/usagebased/detailedline.go
- openmeter/billing/service/invoicecalc/details.go
- test/billing/tax_test.go
- openmeter/billing/adapter/stdinvoicelines.go
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/app/stripe/invoice_test.go (1)
179-207: ⚡ Quick winUse test-scoped context for these new TaxCodeService calls.
These new calls should use
s.T().Context()(or a ctx derived from it) instead of a background context so cancellation/lifecycle is tied to the test harness.As per coding guidelines "
**/*_test.go: Uset.Context()in tests when atesting.Tortesting.TBis available instead of introducingcontext.Background()to keep cancellation and lifecycle tied to the test harness".🤖 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/app/stripe/invoice_test.go` around lines 179 - 207, The new TaxCodeService calls use a background ctx; change them to use the test-scoped context from the test harness by replacing ctx with s.T().Context() (or create a local ctx := s.T().Context() and pass that) for the calls to s.TaxCodeService.CreateTaxCode (both defaultInvoicingTaxCode and defaultCreditGrantTaxCode) and s.TaxCodeService.UpsertOrganizationDefaultTaxCodes so the operations’ lifecycle is tied to the test; ensure any subsequent uses of the variable defaultInvoicingTaxCode/defaultCreditGrantTaxCode still reference the same test-scoped ctx where needed.
🤖 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 `@test/app/stripe/invoice_test.go`:
- Around line 778-783: The test dereferences lineWithDefaultTax after a
non-fatal s.True(found); change the assertions that check lookup success to
fatal assertions (e.g., use s.Require().True(found) or
s.Require().NoError-style) before accessing lo.FromPtr(lineWithDefaultTax...) so
the test stops immediately if lo.Find on expectedInvoiceAddLines fails; apply
the same change to the other similar block around lines 785-790 where a found
boolean is checked before dereferencing the result.
---
Nitpick comments:
In `@test/app/stripe/invoice_test.go`:
- Around line 179-207: The new TaxCodeService calls use a background ctx; change
them to use the test-scoped context from the test harness by replacing ctx with
s.T().Context() (or create a local ctx := s.T().Context() and pass that) for the
calls to s.TaxCodeService.CreateTaxCode (both defaultInvoicingTaxCode and
defaultCreditGrantTaxCode) and
s.TaxCodeService.UpsertOrganizationDefaultTaxCodes so the operations’ lifecycle
is tied to the test; ensure any subsequent uses of the variable
defaultInvoicingTaxCode/defaultCreditGrantTaxCode still reference the same
test-scoped ctx where needed.
🪄 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: f035f0f7-af0c-4d86-99ba-4a829418e43b
📒 Files selected for processing (3)
openmeter/billing/charges/flatfee/adapter/detailedline.goopenmeter/billing/charges/usagebased/adapter/detailedline.gotest/app/stripe/invoice_test.go
💤 Files with no reviewable changes (2)
- openmeter/billing/charges/usagebased/adapter/detailedline.go
- openmeter/billing/charges/flatfee/adapter/detailedline.go
c0deb12 to
399c6f1
Compare
Summary
Validation
Summary by CodeRabbit
Refactor
New Features
Tests