-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: invoice lifecycle #1766
feat: invoice lifecycle #1766
Conversation
b46f243
to
39fc1aa
Compare
39fc1aa
to
a3c6310
Compare
@@ -316,7 +327,119 @@ func (r *adapter) AssociatedLineCounts(ctx context.Context, input billing.Associ | |||
}, nil | |||
} | |||
|
|||
func mapInvoiceFromDB(invoice db.BillingInvoice, expand billing.InvoiceExpand) (billingentity.Invoice, error) { | |||
func (r *adapter) validateUpdateRequest(req billing.UpdateInvoiceAdapterInput, existing *db.BillingInvoice) error { | |||
if !existing.UpdatedAt.Equal(req.UpdatedAt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be Before/After?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope this ensures that the update object that was posted is based on the exact version in the database.
// CalculateDraftUntilIfMissing calculates the draft until date if it is missing. | ||
// If it's set we are not updating it as the user should update that instead of manipulating the | ||
// workflow config. | ||
func CalculateDraftUntilIfMissing(i *Invoice) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: IsAutoDraftAllowed? Or maybe I'm not understanding fully context but naming feels hard to interepret
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What this function does is that it Calculates the Draft Until field If it is Missing from the invoice.
openmeter/billing/service/invoice.go
Outdated
@@ -262,3 +279,91 @@ func (s *Service) gatherInscopeLines(ctx context.Context, input billing.CreateIn | |||
|
|||
return lines, nil | |||
} | |||
|
|||
func (s *Service) getInvoiceFSMWithLock(ctx context.Context, txAdapter billing.Adapter, invoiceID billingentity.InvoiceID) (*InvoiceStateMachine, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: what is FSM? Should we write it out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finite State Machine?
Overview
Implement a basic lifecycle for the invoices with the required hook points for external systems. We are using stateless for state management.
We are using unified trigger names and expose the available next steps as part of the API.
Endpoint fixes
Rename the /workflow/approve to /approve (as it's better aligned with the other endpoints)
Add /retry to retry failed actions after fixing the issues
Invoice changes
The field status field will only contain the main status (draft, issuing, etc)
A statusDetails field will contain the immutability flags, failure flags, extended status value, plus the list of available actions.