Skip to content

feat: make detailed lines reusable - #4186

Merged
turip merged 6 commits into
mainfrom
feat/detailed-line-reuse
Apr 21, 2026
Merged

turip merged 6 commits into
mainfrom
feat/detailed-line-reuse

Conversation

@turip

@turip turip commented Apr 20, 2026 •

Copy link
Copy Markdown
Member

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

  • Refactor
    • Centralized external-ID handling for invoices and lines for consistent persistence, mapping, and API output.
    • Consolidated credits-applied into a single reusable model with validation, cloning, and accurate sum calculation.
    • Introduced a shared detailed-line base and standardized detailed-line category values/defaults across billing and rating for consistent semantics.
  • Tests
    • Updated tests to expect the new standardized category constants and the shared detailed-line composition.

@coderabbitai

coderabbitai Bot commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Centralizes external-ID handling into a new externalid package and Ent mixins, extracts credits models into creditsapplied, introduces stddetailedline types/mixin for a shared detailed-line base, updates Ent schemas and model types to use the new packages, and migrates adapters, mappers, persistence, and tests to the new helpers and types.

Changes

Cohort / File(s) Summary
External ID models & mixins
openmeter/billing/models/externalid/model.go, openmeter/billing/models/externalid/mixin.go
Add JSON types InvoiceExternalIDs/LineExternalIDs, Ent mixins (InvoiceMixin, LineMixin) and generic helpers Create*/Update*/Map* to centralize external-ID create/update/read logic.
Credits model extraction
openmeter/billing/models/creditsapplied/model.go, openmeter/billing/stdinvoicecredits.go
Move CreditsApplied/CreditApplied into creditsapplied package; replace local types with aliases and delegate validation/clone/sum logic to the new package.
Std detailed-line model & mixin
openmeter/billing/models/stddetailedline/model.go, openmeter/billing/models/stddetailedline/mixin.go
Introduce stddetailedline.Category and stddetailedline.Base plus Ent mixin consolidating detailed-line fields (service period, qty, amounts, external IDs, credits, enums, index, DB index).
Ent schema updates
openmeter/ent/schema/billing.go
Replace explicit external-id fields with externalid mixins; switch detailed-line schema to stddetailedline.Mixin; change category enum type/default to stddetailedline.Category.
Adapters & DB mapping
openmeter/billing/adapter/invoice.go, openmeter/billing/adapter/stdinvoicelinemapper.go, openmeter/billing/adapter/stdinvoicelines.go
Delegate invoice/line external-ID create/update/map to externalid helpers instead of inlined SetNillable/SetOrClear calls; mapping reads use externalid.Map*.
Standard invoice & line models
openmeter/billing/stdinvoice.go, openmeter/billing/stdinvoiceline.go, openmeter/billing/invoice.go, openmeter/billing/invoicedetailedline.go, openmeter/billing/invoicelinediscount.go
Replace local InvoiceExternalIDs/LineExternalIDs and FlatFeeCategory with externalid.* and stddetailedline.Category; remove several local helper types/validators/accessors and delegate to shared models.
Invoice line persistence & mappers
openmeter/billing/stdinvoicelines.go, openmeter/billing/adapter/stdinvoicelinemapper.go
Create/upsert builders now call externalid.CreateLineExternalID / externalid.UpdateLineExternalID; mappers use externalid.MapLineExternalIDFromDB.
HTTP mapping helpers
openmeter/billing/httpdriver/invoice.go, openmeter/billing/httpdriver/invoiceline.go
Function signatures updated to accept externalid.* types (imports adjusted); mapping behavior unchanged.
Rating/service & defaults
openmeter/billing/rating/..., openmeter/billing/service/invoicecalc/details.go
Switch category constants and matching logic to stddetailedline.Category*; default fallback values updated to new category type and detailed-line bases now embed stddetailedline.Base.
Generated helpers
openmeter/billing/derived.gen.go
Update generated equality helpers to reference creditsapplied.CreditApplied and adjust helper signatures accordingly.
Tests & fixtures
test/billing/*, openmeter/billing/rating/service/rate/*_test.go, openmeter/billing/rating/service/mutator/credits_test.go, openmeter/billing/stdinvoice_test.go, openmeter/billing/adapter/stdinvoicelinediff_test.go
Update imports and expected Category values to stddetailedline.Category*; refactor fixtures to nest detailed-line Base: stddetailedline.Base{...} where applicable.
Docs / skills
.agents/skills/*
Add guidance to prefer the shared stddetailedline base and reuse mapping helpers across billing and charges adapters.

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

release-note/feature

Suggested reviewers

  • GAlexIHU
  • tothandras
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.59% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: make detailed lines reusable' clearly and concisely describes the main goal of this changeset—refactoring detailed lines into a reusable shared model that can be used across multiple domains.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/detailed-line-reuse

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@turip
turip marked this pull request as ready for review April 20, 2026 15:33
@turip
turip requested a review from a team as a code owner April 20, 2026 15:33
@turip turip added release-note/misc Miscellaneous changes area/billing labels Apr 20, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4516800 and ef0877f.

⛔ Files ignored due to path filters (42)
  • openmeter/ent/db/billinginvoice.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoice/billinginvoice.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoice/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoice_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoice_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig/billinginvoiceflatfeelineconfig.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline/billinginvoiceline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount/billinginvoicelinediscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount/billinginvoicelineusagediscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline/billingstandardinvoicedetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount/billingstandardinvoicedetailedlineamountdiscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/entmixinaccessor.go is excluded by !**/ent/db/**
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/predicate/predicate.go is excluded by !**/ent/db/**
  • openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
  • openmeter/ent/db/setorclear.go is excluded by !**/ent/db/**
📒 Files selected for processing (30)
  • openmeter/billing/adapter/invoice.go
  • openmeter/billing/adapter/stdinvoicelinemapper.go
  • openmeter/billing/adapter/stdinvoicelines.go
  • openmeter/billing/derived.gen.go
  • openmeter/billing/httpdriver/invoice.go
  • openmeter/billing/httpdriver/invoiceline.go
  • openmeter/billing/invoice.go
  • openmeter/billing/invoicedetailedline.go
  • openmeter/billing/invoicelinediscount.go
  • openmeter/billing/models/creditsapplied/model.go
  • openmeter/billing/models/externalid/mixin.go
  • openmeter/billing/models/externalid/model.go
  • openmeter/billing/models/stddetailedline/mixin.go
  • openmeter/billing/models/stddetailedline/model.go
  • openmeter/billing/rating/detailedline.go
  • openmeter/billing/rating/service/detailedline.go
  • openmeter/billing/rating/service/mutator/commitments.go
  • openmeter/billing/rating/service/mutator/credits_test.go
  • openmeter/billing/rating/service/rate/dynamic_test.go
  • openmeter/billing/rating/service/rate/package_test.go
  • openmeter/billing/rating/service/rate/tieredgraduated_test.go
  • openmeter/billing/rating/service/rate/tieredvolume_test.go
  • openmeter/billing/rating/service/rate/unit_test.go
  • openmeter/billing/service/invoicecalc/details.go
  • openmeter/billing/stdinvoice.go
  • openmeter/billing/stdinvoicecredits.go
  • openmeter/billing/stdinvoiceline.go
  • openmeter/ent/schema/billing.go
  • test/billing/adapter_test.go
  • test/billing/invoice_test.go
💤 Files with no reviewable changes (1)
  • openmeter/billing/invoice.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
openmeter/billing/models/creditsapplied/model.go (1)

7-7: ⚠️ Potential issue | 🟡 Minor

Preserve non-nil empty slices in Clone.

len(c) == 0 also catches make(CreditsApplied, 0), so cloning a non-nil empty slice turns it into nil. Since the generated equality logic treats nil and empty credit slices differently, this still changes value semantics. A tiny nil check plus make/copy keeps 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 go

Also 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

📥 Commits

Reviewing files that changed from the base of the PR and between ef0877f and 58b0801.

📒 Files selected for processing (1)
  • openmeter/billing/models/creditsapplied/model.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟠 Major

Add UpdateInvoicingAppExternalID() to all conflict-resolution chains that create external IDs.

The create paths set invoicing_app_external_id via externalid.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 includes UpdateInvoicingAppExternalID(), 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 | 🟡 Minor

Keep Clone from collapsing empty slices to nil.

len(c) == 0 turns a non-nil empty CreditsApplied{} into nil, so cloning can still change value semantics when nil vs empty matters. A tiny nil guard plus make/copy preserves both cases and drops the identity lo.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.go

Also 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

📥 Commits

Reviewing files that changed from the base of the PR and between 58b0801 and f838605.

⛔ Files ignored due to path filters (42)
  • openmeter/ent/db/billinginvoice.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoice/billinginvoice.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoice/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoice_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoice_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig/billinginvoiceflatfeelineconfig.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline/billinginvoiceline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount/billinginvoicelinediscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount/billinginvoicelineusagediscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline/billingstandardinvoicedetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount/billingstandardinvoicedetailedlineamountdiscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/entmixinaccessor.go is excluded by !**/ent/db/**
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/predicate/predicate.go is excluded by !**/ent/db/**
  • openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
  • openmeter/ent/db/setorclear.go is excluded by !**/ent/db/**
📒 Files selected for processing (30)
  • openmeter/billing/adapter/invoice.go
  • openmeter/billing/adapter/stdinvoicelinemapper.go
  • openmeter/billing/adapter/stdinvoicelines.go
  • openmeter/billing/derived.gen.go
  • openmeter/billing/httpdriver/invoice.go
  • openmeter/billing/httpdriver/invoiceline.go
  • openmeter/billing/invoice.go
  • openmeter/billing/invoicedetailedline.go
  • openmeter/billing/invoicelinediscount.go
  • openmeter/billing/models/creditsapplied/model.go
  • openmeter/billing/models/externalid/mixin.go
  • openmeter/billing/models/externalid/model.go
  • openmeter/billing/models/stddetailedline/mixin.go
  • openmeter/billing/models/stddetailedline/model.go
  • openmeter/billing/rating/detailedline.go
  • openmeter/billing/rating/service/detailedline.go
  • openmeter/billing/rating/service/mutator/commitments.go
  • openmeter/billing/rating/service/mutator/credits_test.go
  • openmeter/billing/rating/service/rate/dynamic_test.go
  • openmeter/billing/rating/service/rate/package_test.go
  • openmeter/billing/rating/service/rate/tieredgraduated_test.go
  • openmeter/billing/rating/service/rate/tieredvolume_test.go
  • openmeter/billing/rating/service/rate/unit_test.go
  • openmeter/billing/service/invoicecalc/details.go
  • openmeter/billing/stdinvoice.go
  • openmeter/billing/stdinvoicecredits.go
  • openmeter/billing/stdinvoiceline.go
  • openmeter/ent/schema/billing.go
  • test/billing/adapter_test.go
  • test/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

turip added 4 commits April 20, 2026 19:29
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f838605 and 4e30e53.

⛔ Files ignored due to path filters (88)
  • openmeter/ent/db/billinginvoice.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoice/billinginvoice.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoice/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoice_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoice_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig/billinginvoiceflatfeelineconfig.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceflatfeelineconfig_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline/billinginvoiceline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoiceline_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount/billinginvoicelinediscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelinediscount_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount/billinginvoicelineusagediscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billinginvoicelineusagediscount_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline/billingstandardinvoicedetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedline_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount/billingstandardinvoicedetailedlineamountdiscount.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/billingstandardinvoicedetailedlineamountdiscount_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeedetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeedetailedline/chargeflatfeedetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeedetailedline/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeedetailedline_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeedetailedline_delete.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeedetailedline_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeedetailedline_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebaseddetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebaseddetailedline/chargeusagebaseddetailedline.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebaseddetailedline/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebaseddetailedline_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebaseddetailedline_delete.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebaseddetailedline_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebaseddetailedline_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedruns.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedruns/chargeusagebasedruns.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedruns/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedruns_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedruns_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedruns_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/client.go is excluded by !**/ent/db/**
  • openmeter/ent/db/cursor.go is excluded by !**/ent/db/**
  • openmeter/ent/db/ent.go is excluded by !**/ent/db/**
  • openmeter/ent/db/entmixinaccessor.go is excluded by !**/ent/db/**
  • openmeter/ent/db/expose.go is excluded by !**/ent/db/**
  • openmeter/ent/db/hook/hook.go is excluded by !**/ent/db/**
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/paginate.go is excluded by !**/ent/db/**
  • openmeter/ent/db/predicate/predicate.go is excluded by !**/ent/db/**
  • openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
  • openmeter/ent/db/setorclear.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/tx.go is excluded by !**/ent/db/**
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (35)
  • openmeter/billing/adapter/invoice.go
  • openmeter/billing/adapter/stdinvoicelinemapper.go
  • openmeter/billing/adapter/stdinvoicelines.go
  • openmeter/billing/derived.gen.go
  • openmeter/billing/httpdriver/invoice.go
  • openmeter/billing/httpdriver/invoiceline.go
  • openmeter/billing/invoice.go
  • openmeter/billing/invoicedetailedline.go
  • openmeter/billing/invoicelinediscount.go
  • openmeter/billing/models/creditsapplied/model.go
  • openmeter/billing/models/externalid/mixin.go
  • openmeter/billing/models/externalid/model.go
  • openmeter/billing/models/stddetailedline/mixin.go
  • openmeter/billing/models/stddetailedline/model.go
  • openmeter/billing/rating/detailedline.go
  • openmeter/billing/rating/service/detailedline.go
  • openmeter/billing/rating/service/mutator/commitments.go
  • openmeter/billing/rating/service/mutator/credits_test.go
  • openmeter/billing/rating/service/rate/dynamic_test.go
  • openmeter/billing/rating/service/rate/package_test.go
  • openmeter/billing/rating/service/rate/tieredgraduated_test.go
  • openmeter/billing/rating/service/rate/tieredvolume_test.go
  • openmeter/billing/rating/service/rate/unit_test.go
  • openmeter/billing/service/invoicecalc/details.go
  • openmeter/billing/stdinvoice.go
  • openmeter/billing/stdinvoicecredits.go
  • openmeter/billing/stdinvoiceline.go
  • openmeter/ent/schema/billing.go
  • openmeter/ent/schema/chargesflatfee.go
  • openmeter/ent/schema/chargesusagebased.go
  • openmeter/ent/schema/taxcode.go
  • test/billing/adapter_test.go
  • test/billing/invoice_test.go
  • tools/migrate/migrations/20260420163344_add_charge_detailed_line_tables.down.sql
  • tools/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

@turip
turip enabled auto-merge (squash) April 20, 2026 19:00

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e30e53 and a822acf.

📒 Files selected for processing (10)
  • .agents/skills/billing/SKILL.md
  • .agents/skills/charges/SKILL.md
  • openmeter/billing/adapter/stdinvoicelinediff_test.go
  • openmeter/billing/adapter/stdinvoicelinemapper.go
  • openmeter/billing/derived.gen.go
  • openmeter/billing/invoicedetailedline.go
  • openmeter/billing/models/stddetailedline/model.go
  • openmeter/billing/service/invoicecalc/details.go
  • openmeter/billing/stdinvoice_test.go
  • test/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

@turip
turip merged commit d1f4cd5 into main Apr 21, 2026
22 of 24 checks passed
@turip
turip deleted the feat/detailed-line-reuse branch April 21, 2026 11:21
@turip
turip restored the feat/detailed-line-reuse branch April 21, 2026 11:23

This branch was previously deployed

1 inactive deployment
dev — 85d7bd8d Deployed Apr 21, 2026 by turip via Migration Checks #13680
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants