Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions openmeter/billing/invoiceline.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,19 @@ func (i Line) ValidateFee() error {
errs = append(errs, errors.New("price should be positive or zero"))
}

if !i.FlatFee.Quantity.IsPositive() {
errs = append(errs, errors.New("quantity should be positive required"))
if i.Status == InvoiceLineStatusValid {
// Valid lines (top level invoice lines must have qty=1)
// Given product catalog only supports 1 as quantity, let's restrict ourselves to 1 too
// as the product catalog spec drives billing behavior
if !i.FlatFee.Quantity.Equal(alpacadecimal.NewFromInt(1)) {
errs = append(errs, errors.New("quantity should be 1 for invoice's flat fee lines"))
}
} else {
// detailed lines can have any quantity, but not negative (e.g. unit based price's qty is the
// usage)
if !i.FlatFee.Quantity.IsPositive() {
errs = append(errs, errors.New("quantity should be positive"))
}
}

if !slices.Contains(FlatFeeCategory("").Values(), string(i.FlatFee.Category)) {
Expand Down
6 changes: 3 additions & 3 deletions test/app/custominvoicing/invocing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (s *CustomInvoicingTestSuite) TestInvoicingFlowHooksEnabled() {
Name: "Test item - HUF",

PerUnitAmount: alpacadecimal.NewFromFloat(200),
Quantity: alpacadecimal.NewFromFloat(3),
Quantity: alpacadecimal.NewFromFloat(1),
PaymentTerm: productcatalog.InAdvancePaymentTerm,
}),
{
Expand Down Expand Up @@ -359,8 +359,8 @@ func (s *CustomInvoicingTestSuite) TestInvoicingFlowPaymentStatusOnly() {

Name: "Test item - HUF",

PerUnitAmount: alpacadecimal.NewFromFloat(200),
Quantity: alpacadecimal.NewFromFloat(3),
PerUnitAmount: alpacadecimal.NewFromFloat(600),
Quantity: alpacadecimal.NewFromFloat(1),
PaymentTerm: productcatalog.InAdvancePaymentTerm,
}),
},
Expand Down
4 changes: 2 additions & 2 deletions test/billing/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (s *InvoicingTestSuite) TestPendingLineCreation() {
Name: "Test item - HUF",

PerUnitAmount: alpacadecimal.NewFromFloat(200),
Quantity: alpacadecimal.NewFromFloat(3),
Quantity: alpacadecimal.NewFromFloat(1),
PaymentTerm: productcatalog.InAdvancePaymentTerm,
}),
{
Expand Down Expand Up @@ -493,7 +493,7 @@ func (s *InvoicingTestSuite) TestCreateInvoice() {
Name: "Test item2",

PerUnitAmount: alpacadecimal.NewFromFloat(200),
Quantity: alpacadecimal.NewFromFloat(3),
Quantity: alpacadecimal.NewFromFloat(1),
PaymentTerm: productcatalog.InAdvancePaymentTerm,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion test/billing/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (s *BaseSuite) CreateGatheringInvoice(t *testing.T, ctx context.Context, in
},
FlatFee: &billing.FlatFeeLine{
PerUnitAmount: alpacadecimal.NewFromFloat(200),
Quantity: alpacadecimal.NewFromFloat(3),
Quantity: alpacadecimal.NewFromFloat(1),
Category: billing.FlatFeeCategoryRegular,
PaymentTerm: productcatalog.InAdvancePaymentTerm,
},
Expand Down
Loading