-
Notifications
You must be signed in to change notification settings - Fork 126
Feat Regenerate invoice from voided invoice #3992
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
Conversation
bf7d621
to
8a1a81d
Compare
c3ba468
to
c7bae65
Compare
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.
Pull Request Overview
This PR enables the regeneration of voided invoices with adjusted fee attributes. The feature allows users to correct or adjust values like units, unit_amount_cents, or invoice_display_name after an invoice has been voided.
- Introduces
AdjustedFees::EstimateService
for previewing fee adjustments without persistence - Adds
Invoices::RegenerateFromVoidedService
for rebuilding invoices from voided ones with adjustments - Establishes relationships between original and regenerated invoices via
voided_invoice_id
field
Reviewed Changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 7 comments.
Show a summary per file
File | Description |
---|---|
app/services/adjusted_fees/estimate_service.rb |
New service for calculating adjusted fee estimates |
app/services/invoices/regenerate_from_voided_service.rb |
Core service for regenerating invoices from voided ones |
app/graphql/mutations/adjusted_fees/preview.rb |
GraphQL mutation for previewing adjusted fees |
app/graphql/mutations/invoices/regenerate_from_voided.rb |
GraphQL mutation for regenerating invoices |
app/models/invoice.rb |
Adds association to track regenerated invoices |
app/services/invoices/create_one_off_service.rb |
Adds support for voided_invoice_id parameter |
Various GraphQL types and schema files | Adds new input types and fields for the feature |
Spec files | Comprehensive test coverage for new services and mutations |
Context
Currently, when voiding an invoice, it’s not possible to regenerate it with updated fee attributes. This limitation creates friction for users who want to correct or adjust values such as units, unit_amount_cents, or invoice_display_name after an invoice has already been issued and voided.
Description
This PR introduces two new services that enable the regeneration of a voided invoice with adjusted fee values:
AdjustedFees::EstimateService
This service is used to preview how a fee would be adjusted before persisting any data. It handles all necessary backend calculations—such as tax application, amount breakdown, and unit price derivation—based on the provided input. It is designed to be used by the frontend to fetch real-time estimates while the user is making adjustments to fees.
Invoices::RegenerateFromVoidedService
This service is responsible for actually rebuilding the invoice from a voided one. It:
• Duplicates relevant fee records,
• Applies adjustments coming from the frontend (e.g., new units, updated unit_amount_cents, or invoice_display_name),
• Recalculates all fee amounts, taxes, and totals,
• Applies coupons, credit notes, and prepaid credits if applicable,
• Transitions the invoice to the appropriate payment status (pending or succeeded).