Skip to content

Conversation

brunomiguelpinto
Copy link
Contributor

@brunomiguelpinto brunomiguelpinto commented Jul 14, 2025

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).

@brunomiguelpinto brunomiguelpinto self-assigned this Jul 31, 2025
@brunomiguelpinto brunomiguelpinto force-pushed the feat-regenerate-code-cleaning branch 4 times, most recently from bf7d621 to 8a1a81d Compare August 5, 2025 08:07
@brunomiguelpinto brunomiguelpinto changed the title wip: code cleaning Feat Regenerate invoice from voided invoice Aug 5, 2025
@brunomiguelpinto brunomiguelpinto force-pushed the feat-regenerate-code-cleaning branch from c3ba468 to c7bae65 Compare August 5, 2025 16:21
Copy link

@Copilot Copilot AI left a 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

@brunomiguelpinto brunomiguelpinto merged commit 5b5f324 into main Aug 6, 2025
14 checks passed
@brunomiguelpinto brunomiguelpinto deleted the feat-regenerate-code-cleaning branch August 6, 2025 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants