Repository navigation
feat: make detailed lines reusable - #4186
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughCentralizes external-ID handling into a new Changes
Sequence Diagram(s)(omitted — changes are refactors of types/mixins/schema and mapping, not a new multi-component sequential flow) Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@openmeter/billing/models/creditsapplied/model.go`:
- Line 7: The clone implementation currently uses lo.Map to clone the credit
slice which converts a nil slice to an empty non-nil slice; update the cloning
code (the Clone/DeepCopy method where lo.Map is used) to check if the original
slice is nil before mapping and preserve nil by returning nil (or leaving the
field nil) when the source slice is nil, otherwise use lo.Map to produce the
cloned slice; reference the slice variable (e.g., Credits or credits) and the
use of lo.Map in the Clone/DeepCopy function to locate and apply this nil guard.
In `@openmeter/billing/models/externalid/mixin.go`:
- Around line 52-98: The InvoiceExternalIDs type and helpers are missing the tax
external id; add a Tax string field to InvoiceExternalIDs and update the
interfaces and helpers: extend InvoiceExternalIDCreator to include
SetNillableTaxAppExternalID(*string), extend InvoiceExternalIDUpdater to include
SetOrClearTaxAppExternalID(*string), and extend InvoiceExternalIDGetter to
include GetTaxAppExternalID() *string; then modify CreateInvoiceExternalID and
UpdateInvoiceExternalID to call the new SetNillable/SetOrClearTaxAppExternalID
using lo.EmptyableToPtr(ids.Tax), and modify MapInvoiceExternalIDFromDB to
populate InvoiceExternalIDs.Tax using
lo.FromPtr(dbEntity.GetTaxAppExternalID()). Ensure method names match the
generated ent setters/getters (TaxAppExternalID variants) used in the schema.
🪄 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: 76555371-0edb-4128-9764-b84b675c01c3
⛔ Files ignored due to path filters (42)
openmeter/ent/db/billinginvoice.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoice/billinginvoice.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoice/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoice_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoice_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig/billinginvoiceflatfeelineconfig.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline/billinginvoiceline.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount/billinginvoicelinediscount.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount/billinginvoicelineusagediscount.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount_update.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline/billingstandardinvoicedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline/where.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_create.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_query.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_update.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount/billingstandardinvoicedetailedlineamountdiscount.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount/where.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount_create.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount_update.gois excluded by!**/ent/db/**openmeter/ent/db/entmixinaccessor.gois excluded by!**/ent/db/**openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/predicate/predicate.gois excluded by!**/ent/db/**openmeter/ent/db/runtime.gois excluded by!**/ent/db/**openmeter/ent/db/setorclear.gois excluded by!**/ent/db/**
📒 Files selected for processing (30)
openmeter/billing/adapter/invoice.goopenmeter/billing/adapter/stdinvoicelinemapper.goopenmeter/billing/adapter/stdinvoicelines.goopenmeter/billing/derived.gen.goopenmeter/billing/httpdriver/invoice.goopenmeter/billing/httpdriver/invoiceline.goopenmeter/billing/invoice.goopenmeter/billing/invoicedetailedline.goopenmeter/billing/invoicelinediscount.goopenmeter/billing/models/creditsapplied/model.goopenmeter/billing/models/externalid/mixin.goopenmeter/billing/models/externalid/model.goopenmeter/billing/models/stddetailedline/mixin.goopenmeter/billing/models/stddetailedline/model.goopenmeter/billing/rating/detailedline.goopenmeter/billing/rating/service/detailedline.goopenmeter/billing/rating/service/mutator/commitments.goopenmeter/billing/rating/service/mutator/credits_test.goopenmeter/billing/rating/service/rate/dynamic_test.goopenmeter/billing/rating/service/rate/package_test.goopenmeter/billing/rating/service/rate/tieredgraduated_test.goopenmeter/billing/rating/service/rate/tieredvolume_test.goopenmeter/billing/rating/service/rate/unit_test.goopenmeter/billing/service/invoicecalc/details.goopenmeter/billing/stdinvoice.goopenmeter/billing/stdinvoicecredits.goopenmeter/billing/stdinvoiceline.goopenmeter/ent/schema/billing.gotest/billing/adapter_test.gotest/billing/invoice_test.go
💤 Files with no reviewable changes (1)
- openmeter/billing/invoice.go
58b0801 to
f838605
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
openmeter/billing/models/creditsapplied/model.go (1)
7-7:⚠️ Potential issue | 🟡 MinorPreserve non-nil empty slices in
Clone.
len(c) == 0also catchesmake(CreditsApplied, 0), so cloning a non-nil empty slice turns it intonil. Since the generated equality logic treats nil and empty credit slices differently, this still changes value semantics. A tinynilcheck plusmake/copykeeps both cases intact.Suggested fix
import ( "errors" "github.com/alpacahq/alpacadecimal" - "github.com/samber/lo" "github.com/openmeterio/openmeter/pkg/currencyx" "github.com/openmeterio/openmeter/pkg/models" ) @@ func (c CreditsApplied) Clone() CreditsApplied { - if len(c) == 0 { + if c == nil { return nil } - return lo.Map(c, func(item CreditApplied, _ int) CreditApplied { - return item - }) + clone := make(CreditsApplied, len(c)) + copy(clone, c) + + return clone }You can verify the nil-vs-empty equality assumption with:
#!/bin/bash # Description: Inspect the generated equality helper and current Clone implementation. # Expect: equality distinguishes nil from empty slices, while Clone currently returns nil for len==0. rg -n -C 4 'func .*CreditsApplied.*Equal|CreditsApplied.*== nil|len\(c\) == 0|func \(c CreditsApplied\) Clone' --type goAlso applies to: 30-37
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/billing/models/creditsapplied/model.go` at line 7, The Clone implementation for type CreditsApplied currently treats any zero-length slice the same and returns nil, which loses the distinction between nil and non-nil empty slices; update the CreditsApplied.Clone method(s) to first check if the receiver is nil and return nil in that case, otherwise allocate a new slice with make(CreditsApplied, len(c)) and copy(copied, c) so a non-nil zero-length slice stays non-nil after cloning; apply the same nil-vs-empty-preserving logic to any other Clone variants in the file (the CreditsApplied Clone functions around lines 30-37).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@openmeter/billing/models/creditsapplied/model.go`:
- Line 7: The Clone implementation for type CreditsApplied currently treats any
zero-length slice the same and returns nil, which loses the distinction between
nil and non-nil empty slices; update the CreditsApplied.Clone method(s) to first
check if the receiver is nil and return nil in that case, otherwise allocate a
new slice with make(CreditsApplied, len(c)) and copy(copied, c) so a non-nil
zero-length slice stays non-nil after cloning; apply the same
nil-vs-empty-preserving logic to any other Clone variants in the file (the
CreditsApplied Clone functions around lines 30-37).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 05b12c07-ab24-458c-8d28-be8459ae53b7
📒 Files selected for processing (1)
openmeter/billing/models/creditsapplied/model.go
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
openmeter/billing/adapter/stdinvoicelines.go (1)
85-155:⚠️ Potential issue | 🟠 MajorAdd
UpdateInvoicingAppExternalID()to all conflict-resolution chains that create external IDs.The create paths set
invoicing_app_external_idviaexternalid.CreateLineExternalID(), but the selected-field upsert chains don't explicitly update it on conflict. Since the existing TODO flags that nillable fields must be listed explicitly, and the v2 amount-discount path already includesUpdateInvoicingAppExternalID(), the same needs adding to the other selected-field conflict chains.Proposed fix
Add
UpdateInvoicingAppExternalID()to the conflict chains at lines 154, 355, and 469:UpdateTaxBehavior(). + UpdateInvoicingAppExternalID(). Exec(ctx)UpdateTaxBehavior(). + UpdateInvoicingAppExternalID(). Exec(ctx)UpdateIndex(). UpdateDeletedAt(). + UpdateInvoicingAppExternalID(). Exec(ctx)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/billing/adapter/stdinvoicelines.go` around lines 85 - 155, The conflict-resolution chains that call externalid.CreateLineExternalID() do not include UpdateInvoicingAppExternalID(), so invoicing_app_external_id isn’t updated on conflict; add .UpdateInvoicingAppExternalID() into each OnConflict(...).Resolve... chain that currently ends with calls like UpdateQuantity().UpdateChildUniqueReferenceID()... before Exec(); specifically update the UpsertItems conflict chain (the CreateBulk(...).OnConflict(...).ResolveWith(...) chain in the UpsertItems function) and the two other similar CreateBulk/OnConflict upsert chains (the other upsert helper functions that mirror this pattern) to include UpdateInvoicingAppExternalID() alongside the other Update* calls.
♻️ Duplicate comments (1)
openmeter/billing/models/creditsapplied/model.go (1)
7-7:⚠️ Potential issue | 🟡 MinorKeep
Clonefrom collapsing empty slices to nil.
len(c) == 0turns a non-nil emptyCreditsApplied{}intonil, so cloning can still change value semantics when nil vs empty matters. A tiny nil guard plusmake/copypreserves both cases and drops the identitylo.Map.Suggested fix
import ( "errors" "github.com/alpacahq/alpacadecimal" - "github.com/samber/lo" "github.com/openmeterio/openmeter/pkg/currencyx" "github.com/openmeterio/openmeter/pkg/models" ) @@ func (c CreditsApplied) Clone() CreditsApplied { - if len(c) == 0 { + if c == nil { return nil } - return lo.Map(c, func(item CreditApplied, _ int) CreditApplied { - return item - }) + out := make(CreditsApplied, len(c)) + copy(out, c) + + return out }You can verify the surrounding generated equality/value semantics with:
#!/bin/bash # Description: Inspect the clone implementation and generated CreditsApplied equality helpers. # Expected: Generated helpers distinguish nil and empty slices, so Clone should preserve that distinction. sed -n '30,38p' openmeter/billing/models/creditsapplied/model.go rg -n -C 6 'CreditsApplied|CreditApplied|Equal' openmeter/billing/derived.gen.goAlso applies to: 30-38
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/billing/models/creditsapplied/model.go` at line 7, The Clone implementation for CreditsApplied currently uses len(c) == 0 and lo.Map which collapses a non-nil empty slice into nil; update the CreditsApplied.Clone to preserve nil vs non-nil-empty semantics by adding a nil guard: if the receiver is nil return nil, otherwise if the slice length is zero return a new non-nil empty CreditsApplied (allocate with make and copy as needed) and for non-empty slices allocate with make and copy the elements (avoid lo.Map) so the cloned CreditsApplied maintains identity differences expected by the generated Equal helpers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@openmeter/billing/adapter/stdinvoicelines.go`:
- Around line 85-155: The conflict-resolution chains that call
externalid.CreateLineExternalID() do not include UpdateInvoicingAppExternalID(),
so invoicing_app_external_id isn’t updated on conflict; add
.UpdateInvoicingAppExternalID() into each OnConflict(...).Resolve... chain that
currently ends with calls like
UpdateQuantity().UpdateChildUniqueReferenceID()... before Exec(); specifically
update the UpsertItems conflict chain (the
CreateBulk(...).OnConflict(...).ResolveWith(...) chain in the UpsertItems
function) and the two other similar CreateBulk/OnConflict upsert chains (the
other upsert helper functions that mirror this pattern) to include
UpdateInvoicingAppExternalID() alongside the other Update* calls.
---
Duplicate comments:
In `@openmeter/billing/models/creditsapplied/model.go`:
- Line 7: The Clone implementation for CreditsApplied currently uses len(c) == 0
and lo.Map which collapses a non-nil empty slice into nil; update the
CreditsApplied.Clone to preserve nil vs non-nil-empty semantics by adding a nil
guard: if the receiver is nil return nil, otherwise if the slice length is zero
return a new non-nil empty CreditsApplied (allocate with make and copy as
needed) and for non-empty slices allocate with make and copy the elements (avoid
lo.Map) so the cloned CreditsApplied maintains identity differences expected by
the generated Equal helpers.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c0db1685-c405-4a1d-9eec-e808824dc4f0
⛔ Files ignored due to path filters (42)
openmeter/ent/db/billinginvoice.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoice/billinginvoice.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoice/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoice_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoice_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig/billinginvoiceflatfeelineconfig.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline/billinginvoiceline.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount/billinginvoicelinediscount.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount/billinginvoicelineusagediscount.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount_update.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline/billingstandardinvoicedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline/where.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_create.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_query.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_update.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount/billingstandardinvoicedetailedlineamountdiscount.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount/where.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount_create.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount_update.gois excluded by!**/ent/db/**openmeter/ent/db/entmixinaccessor.gois excluded by!**/ent/db/**openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/predicate/predicate.gois excluded by!**/ent/db/**openmeter/ent/db/runtime.gois excluded by!**/ent/db/**openmeter/ent/db/setorclear.gois excluded by!**/ent/db/**
📒 Files selected for processing (30)
openmeter/billing/adapter/invoice.goopenmeter/billing/adapter/stdinvoicelinemapper.goopenmeter/billing/adapter/stdinvoicelines.goopenmeter/billing/derived.gen.goopenmeter/billing/httpdriver/invoice.goopenmeter/billing/httpdriver/invoiceline.goopenmeter/billing/invoice.goopenmeter/billing/invoicedetailedline.goopenmeter/billing/invoicelinediscount.goopenmeter/billing/models/creditsapplied/model.goopenmeter/billing/models/externalid/mixin.goopenmeter/billing/models/externalid/model.goopenmeter/billing/models/stddetailedline/mixin.goopenmeter/billing/models/stddetailedline/model.goopenmeter/billing/rating/detailedline.goopenmeter/billing/rating/service/detailedline.goopenmeter/billing/rating/service/mutator/commitments.goopenmeter/billing/rating/service/mutator/credits_test.goopenmeter/billing/rating/service/rate/dynamic_test.goopenmeter/billing/rating/service/rate/package_test.goopenmeter/billing/rating/service/rate/tieredgraduated_test.goopenmeter/billing/rating/service/rate/tieredvolume_test.goopenmeter/billing/rating/service/rate/unit_test.goopenmeter/billing/service/invoicecalc/details.goopenmeter/billing/stdinvoice.goopenmeter/billing/stdinvoicecredits.goopenmeter/billing/stdinvoiceline.goopenmeter/ent/schema/billing.gotest/billing/adapter_test.gotest/billing/invoice_test.go
💤 Files with no reviewable changes (1)
- openmeter/billing/invoice.go
✅ Files skipped from review due to trivial changes (10)
- openmeter/billing/httpdriver/invoice.go
- openmeter/billing/adapter/stdinvoicelinemapper.go
- test/billing/invoice_test.go
- openmeter/billing/models/stddetailedline/model.go
- openmeter/billing/httpdriver/invoiceline.go
- openmeter/billing/service/invoicecalc/details.go
- openmeter/billing/rating/service/rate/tieredvolume_test.go
- openmeter/billing/rating/service/mutator/commitments.go
- openmeter/billing/models/externalid/model.go
- openmeter/billing/models/externalid/mixin.go
🚧 Files skipped from review as they are similar to previous changes (9)
- test/billing/adapter_test.go
- openmeter/billing/rating/service/rate/dynamic_test.go
- openmeter/billing/invoicelinediscount.go
- openmeter/billing/rating/service/mutator/credits_test.go
- openmeter/billing/stdinvoiceline.go
- openmeter/billing/stdinvoicecredits.go
- openmeter/billing/derived.gen.go
- openmeter/billing/rating/service/rate/package_test.go
- openmeter/billing/models/stddetailedline/mixin.go
This allows us to presist them as part of charges and rely on them when we need to calculate them as part of the new rating logic.
f838605 to
4e30e53
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@openmeter/billing/models/stddetailedline/mixin.go`:
- Around line 64-87: The schema currently defines the fields quantity and
per_unit_amount as required (field.Other("quantity", alpacadecimal.Decimal{})
and field.Other("per_unit_amount", alpacadecimal.Decimal{})); make both optional
by adding .Optional().Nillable() to each field declaration so they can be nil
until invoice time, then run Ent codegen to regenerate the getters/setters so
they work with pointer/nullable types for these alpacadecimal.Decimal fields.
🪄 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: 162c3bf9-da41-49e8-ace4-55a75e8aa53d
⛔ Files ignored due to path filters (88)
openmeter/ent/db/billinginvoice.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoice/billinginvoice.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoice/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoice_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoice_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig/billinginvoiceflatfeelineconfig.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceflatfeelineconfig_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline/billinginvoiceline.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount/billinginvoicelinediscount.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelinediscount_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount/billinginvoicelineusagediscount.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicelineusagediscount_update.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline/billingstandardinvoicedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline/where.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_create.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_query.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_update.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount/billingstandardinvoicedetailedlineamountdiscount.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount/where.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount_create.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeedetailedline/chargeflatfeedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeedetailedline/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeedetailedline_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeedetailedline_delete.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeedetailedline_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeedetailedline_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebaseddetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebaseddetailedline/chargeusagebaseddetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebaseddetailedline/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebaseddetailedline_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebaseddetailedline_delete.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebaseddetailedline_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebaseddetailedline_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedruns.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedruns/chargeusagebasedruns.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedruns/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedruns_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedruns_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedruns_update.gois excluded by!**/ent/db/**openmeter/ent/db/client.gois excluded by!**/ent/db/**openmeter/ent/db/cursor.gois excluded by!**/ent/db/**openmeter/ent/db/ent.gois excluded by!**/ent/db/**openmeter/ent/db/entmixinaccessor.gois excluded by!**/ent/db/**openmeter/ent/db/expose.gois excluded by!**/ent/db/**openmeter/ent/db/hook/hook.gois excluded by!**/ent/db/**openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/paginate.gois excluded by!**/ent/db/**openmeter/ent/db/predicate/predicate.gois excluded by!**/ent/db/**openmeter/ent/db/runtime.gois excluded by!**/ent/db/**openmeter/ent/db/setorclear.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/where.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_create.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_query.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_update.gois excluded by!**/ent/db/**openmeter/ent/db/tx.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (35)
openmeter/billing/adapter/invoice.goopenmeter/billing/adapter/stdinvoicelinemapper.goopenmeter/billing/adapter/stdinvoicelines.goopenmeter/billing/derived.gen.goopenmeter/billing/httpdriver/invoice.goopenmeter/billing/httpdriver/invoiceline.goopenmeter/billing/invoice.goopenmeter/billing/invoicedetailedline.goopenmeter/billing/invoicelinediscount.goopenmeter/billing/models/creditsapplied/model.goopenmeter/billing/models/externalid/mixin.goopenmeter/billing/models/externalid/model.goopenmeter/billing/models/stddetailedline/mixin.goopenmeter/billing/models/stddetailedline/model.goopenmeter/billing/rating/detailedline.goopenmeter/billing/rating/service/detailedline.goopenmeter/billing/rating/service/mutator/commitments.goopenmeter/billing/rating/service/mutator/credits_test.goopenmeter/billing/rating/service/rate/dynamic_test.goopenmeter/billing/rating/service/rate/package_test.goopenmeter/billing/rating/service/rate/tieredgraduated_test.goopenmeter/billing/rating/service/rate/tieredvolume_test.goopenmeter/billing/rating/service/rate/unit_test.goopenmeter/billing/service/invoicecalc/details.goopenmeter/billing/stdinvoice.goopenmeter/billing/stdinvoicecredits.goopenmeter/billing/stdinvoiceline.goopenmeter/ent/schema/billing.goopenmeter/ent/schema/chargesflatfee.goopenmeter/ent/schema/chargesusagebased.goopenmeter/ent/schema/taxcode.gotest/billing/adapter_test.gotest/billing/invoice_test.gotools/migrate/migrations/20260420163344_add_charge_detailed_line_tables.down.sqltools/migrate/migrations/20260420163344_add_charge_detailed_line_tables.up.sql
💤 Files with no reviewable changes (1)
- openmeter/billing/invoice.go
✅ Files skipped from review due to trivial changes (7)
- openmeter/billing/service/invoicecalc/details.go
- openmeter/billing/rating/service/mutator/commitments.go
- openmeter/billing/rating/service/rate/package_test.go
- openmeter/billing/httpdriver/invoice.go
- openmeter/billing/rating/service/rate/dynamic_test.go
- openmeter/billing/models/stddetailedline/model.go
- openmeter/billing/models/externalid/model.go
🚧 Files skipped from review as they are similar to previous changes (10)
- openmeter/billing/httpdriver/invoiceline.go
- openmeter/billing/invoicelinediscount.go
- openmeter/billing/stdinvoice.go
- openmeter/billing/derived.gen.go
- openmeter/billing/rating/detailedline.go
- openmeter/billing/adapter/stdinvoicelinemapper.go
- openmeter/billing/adapter/stdinvoicelines.go
- openmeter/billing/stdinvoiceline.go
- openmeter/billing/models/externalid/mixin.go
- openmeter/billing/models/creditsapplied/model.go
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@openmeter/billing/models/stddetailedline/model.go`:
- Around line 118-120: Base.Equal currently uses reflect.DeepEqual which
bypasses domain-specific equality semantics; replace its body with a
field-by-field comparison mirroring deriveEqualLineBase from derived.gen.go:
call ManagedModel.Equal (or ManagedModel fields' .Equal) for the managed model,
ClosedPeriod.Equal for service period/timestamps, TaxConfig.Equal for tax
config, compare external ID pointers with nil checks and string equality, and
directly compare simple scalar fields; ensure all pointer fields are nil-safe
and that DetailedLineBase.Equal (which delegates here) inherits these semantics.
🪄 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: 908a7809-55b5-4fde-8b6c-0ab1472ce358
📒 Files selected for processing (10)
.agents/skills/billing/SKILL.md.agents/skills/charges/SKILL.mdopenmeter/billing/adapter/stdinvoicelinediff_test.goopenmeter/billing/adapter/stdinvoicelinemapper.goopenmeter/billing/derived.gen.goopenmeter/billing/invoicedetailedline.goopenmeter/billing/models/stddetailedline/model.goopenmeter/billing/service/invoicecalc/details.goopenmeter/billing/stdinvoice_test.gotest/billing/adapter_test.go
✅ Files skipped from review due to trivial changes (2)
- .agents/skills/charges/SKILL.md
- .agents/skills/billing/SKILL.md
🚧 Files skipped from review as they are similar to previous changes (2)
- openmeter/billing/service/invoicecalc/details.go
- openmeter/billing/adapter/stdinvoicelinemapper.go
Overview
This allows us to presist them as part of charges and rely on them when we need to calculate them as part of the new rating logic.
Notes for reviewer
Summary by CodeRabbit