Skip to content
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

Merged
merged 4 commits into from
Oct 30, 2024
Merged

feat: invoice lifecycle #1766

merged 4 commits into from
Oct 30, 2024

Conversation

turip
Copy link
Contributor

@turip turip commented Oct 29, 2024

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.

@turip turip force-pushed the feat/invoice-lifecycle branch 5 times, most recently from b46f243 to 39fc1aa Compare October 30, 2024 14:09
@turip turip added release-note/feature Release note: Exciting New Features area/billing labels Oct 30, 2024
@turip turip changed the title Feat/invoice lifecycle feat: invoice lifecycle Oct 30, 2024
@turip turip requested a review from hekike October 30, 2024 14:21
@turip turip marked this pull request as ready for review October 30, 2024 14:21
@turip turip force-pushed the feat/invoice-lifecycle branch from 39fc1aa to a3c6310 Compare October 30, 2024 14:35
@turip
Copy link
Contributor Author

turip commented Oct 30, 2024

@hekike the API changes are moved here: #1768

@@ -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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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

Copy link
Contributor Author

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.

@@ -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) {
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

Finite State Machine?

hekike
hekike previously approved these changes Oct 30, 2024
@turip turip enabled auto-merge (squash) October 30, 2024 15:49
@turip turip merged commit a5488ba into main Oct 30, 2024
18 checks passed
@turip turip deleted the feat/invoice-lifecycle branch October 30, 2024 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/billing release-note/feature Release note: Exciting New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants