Skip to content

Commit bfb8127

Browse files
authored
feat: add metered quantity field (#2630)
1 parent a273e05 commit bfb8127

23 files changed

+1885
-1525
lines changed

api/api.gen.go

+965-961
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/client/go/client.gen.go

+562-558
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/client/javascript/src/client/schemas.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5703,6 +5703,8 @@ export interface components {
57035703
rateCard?: components['schemas']['InvoiceUsageBasedRateCard']
57045704
/** @description The quantity of the item being sold. */
57055705
readonly quantity?: components['schemas']['Numeric']
5706+
/** @description The quantity of the item that has been metered for the period before any discounts were applied. */
5707+
readonly meteredQuantity?: components['schemas']['Numeric']
57065708
/** @description The quantity of the item used in before this line's period.
57075709
*
57085710
* It is non-zero in case of progressive billing, when this shows how much of the usage was already billed. */

api/openapi.cloud.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -15466,6 +15466,11 @@ components:
1546615466
- $ref: '#/components/schemas/Numeric'
1546715467
description: The quantity of the item being sold.
1546815468
readOnly: true
15469+
meteredQuantity:
15470+
allOf:
15471+
- $ref: '#/components/schemas/Numeric'
15472+
description: The quantity of the item that has been metered for the period before any discounts were applied.
15473+
readOnly: true
1546915474
preLinePeriodQuantity:
1547015475
allOf:
1547115476
- $ref: '#/components/schemas/Numeric'

api/openapi.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -15540,6 +15540,11 @@ components:
1554015540
- $ref: '#/components/schemas/Numeric'
1554115541
description: The quantity of the item being sold.
1554215542
readOnly: true
15543+
meteredQuantity:
15544+
allOf:
15545+
- $ref: '#/components/schemas/Numeric'
15546+
description: The quantity of the item that has been metered for the period before any discounts were applied.
15547+
readOnly: true
1554315548
preLinePeriodQuantity:
1554415549
allOf:
1554515550
- $ref: '#/components/schemas/Numeric'

api/spec/src/billing/invoices/invoice.tsp

+6
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,12 @@ model InvoiceUsageBasedLine {
748748
@visibility(Lifecycle.Read)
749749
quantity?: Numeric;
750750

751+
/**
752+
* The quantity of the item that has been metered for the period before any discounts were applied.
753+
*/
754+
@visibility(Lifecycle.Read)
755+
meteredQuantity?: Numeric;
756+
751757
/**
752758
* The quantity of the item used in before this line's period.
753759
*

openmeter/billing/adapter/invoicelinemapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ func (a *adapter) mapInvoiceLineWithoutReferences(dbLine *db.BillingInvoiceLine)
203203
FeatureKey: ubpLine.FeatureKey,
204204
Price: ubpLine.Price,
205205
Quantity: dbLine.Quantity,
206+
MeteredQuantity: ubpLine.MeteredQuantity,
206207
PreLinePeriodQuantity: ubpLine.PreLinePeriodQuantity,
207208
}
208209
default:

openmeter/billing/adapter/invoicelines.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ func (a *adapter) upsertUsageBasedConfig(ctx context.Context, lineDiffs diff[*bi
316316
SetPrice(line.UsageBased.Price).
317317
SetFeatureKey(line.UsageBased.FeatureKey).
318318
SetID(line.UsageBased.ConfigID).
319-
SetNillablePreLinePeriodQuantity(line.UsageBased.PreLinePeriodQuantity)
319+
SetNillablePreLinePeriodQuantity(line.UsageBased.PreLinePeriodQuantity).
320+
SetNillableMeteredQuantity(line.UsageBased.MeteredQuantity)
320321

321322
return create, nil
322323
},

openmeter/billing/httpdriver/invoiceline.go

+1
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ func mapUsageBasedLineToAPI(line *billing.Line) (api.InvoiceLine, error) {
377377
TaxConfig: mapTaxConfigToAPI(line.TaxConfig),
378378

379379
FeatureKey: lo.ToPtr(line.UsageBased.FeatureKey),
380+
MeteredQuantity: decimalPtrToStringPtr(line.UsageBased.MeteredQuantity),
380381
Quantity: decimalPtrToStringPtr(line.UsageBased.Quantity),
381382
PreLinePeriodQuantity: decimalPtrToStringPtr(line.UsageBased.PreLinePeriodQuantity),
382383
Price: lo.ToPtr(price),

openmeter/billing/invoiceline.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/openmeterio/openmeter/openmeter/productcatalog"
1515
"github.com/openmeterio/openmeter/pkg/currencyx"
16+
"github.com/openmeterio/openmeter/pkg/equal"
1617
"github.com/openmeterio/openmeter/pkg/models"
1718
)
1819

@@ -702,6 +703,7 @@ type UsageBasedLine struct {
702703
Price *Price `json:"price"`
703704
FeatureKey string `json:"featureKey"`
704705
Quantity *alpacadecimal.Decimal `json:"quantity"`
706+
MeteredQuantity *alpacadecimal.Decimal `json:"meteredQuantity,omitempty"`
705707
PreLinePeriodQuantity *alpacadecimal.Decimal `json:"preLinePeriodQuantity,omitempty"`
706708
}
707709

@@ -710,7 +712,27 @@ func (i UsageBasedLine) Equal(other *UsageBasedLine) bool {
710712
return false
711713
}
712714

713-
return reflect.DeepEqual(i, *other)
715+
if !i.Price.Equal(other.Price) {
716+
return false
717+
}
718+
719+
if i.FeatureKey != other.FeatureKey {
720+
return false
721+
}
722+
723+
if !equal.PtrEqual(i.Quantity, other.Quantity) {
724+
return false
725+
}
726+
727+
if !equal.PtrEqual(i.MeteredQuantity, other.MeteredQuantity) {
728+
return false
729+
}
730+
731+
if !equal.PtrEqual(i.PreLinePeriodQuantity, other.PreLinePeriodQuantity) {
732+
return false
733+
}
734+
735+
return true
714736
}
715737

716738
func (i UsageBasedLine) Clone() *UsageBasedLine {

openmeter/billing/service/lineservice/usagebasedline.go

+2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ func (l *usageBasedLine) SnapshotQuantity(ctx context.Context, invoice *billing.
199199
return err
200200
}
201201

202+
// MeteredQuantity is not mutable by the price mutators, that's why we have this redundancy
203+
l.line.UsageBased.MeteredQuantity = lo.ToPtr(usage.LinePeriodQty)
202204
l.line.UsageBased.Quantity = lo.ToPtr(usage.LinePeriodQty)
203205
l.line.UsageBased.PreLinePeriodQuantity = lo.ToPtr(usage.PreLinePeriodQty)
204206

openmeter/ent/db/billinginvoiceusagebasedlineconfig.go

+16-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openmeter/ent/db/billinginvoiceusagebasedlineconfig/billinginvoiceusagebasedlineconfig.go

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openmeter/ent/db/billinginvoiceusagebasedlineconfig/where.go

+55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openmeter/ent/db/billinginvoiceusagebasedlineconfig_create.go

+78
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)