Skip to content
Merged
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
16 changes: 16 additions & 0 deletions openmeter/billing/service/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,22 @@ func (s *Service) UpdateInvoice(ctx context.Context, input billing.UpdateInvoice
return billing.Invoice{}, fmt.Errorf("fetching invoice: %w", err)
}

// We have requested the invoice to include the split lines, and GetInvoiceByID will also expand
// the sub-lines. However given split lines are cross invoice, those should not be edited via single
// invoice update calls, so we strip the child line information from the invoice. This signals the adapter
// that we are not trying to edit the child lines, thus it will not throw an error for the operation.

invoice.Lines = billing.NewLineChildren(lo.Map(invoice.Lines.OrEmpty(), func(line *billing.Line, _ int) *billing.Line {
if line.Status != billing.InvoiceLineStatusSplit {
return line
}

// This makes the line children not present in the invoice
line.Children = billing.LineChildren{}

return line
}))

if err := input.EditFn(&invoice); err != nil {
return billing.Invoice{}, fmt.Errorf("editing invoice: %w", err)
}
Expand Down
Loading