-
Notifications
You must be signed in to change notification settings - Fork 138
feat(issuing-date-4): Update issuing_date logic to use subscription_invoice_issuing_date settings #4624
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
Open
vankiru
wants to merge
22
commits into
main
Choose a base branch
from
feat/invoice-issuing-date-4-logic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,761
−515
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
groyoh
reviewed
Nov 18, 2025
spec/services/invoices/update_issuing_date_from_billing_entity_service_spec.rb
Show resolved
Hide resolved
eecc812 to
bfe79b8
Compare
groyoh
reviewed
Nov 21, 2025
app/jobs/invoices/update_all_invoice_grace_period_from_billing_entity_job.rb
Show resolved
Hide resolved
app/jobs/invoices/update_issuing_date_from_billing_entity_job.rb
Outdated
Show resolved
Hide resolved
spec/services/billing_entities/update_invoice_issuing_date_settings_service_spec.rb
Outdated
Show resolved
Hide resolved
spec/services/billing_entities/update_invoice_issuing_date_settings_service_spec.rb
Outdated
Show resolved
Hide resolved
spec/services/customers/update_invoice_issuing_date_settings_service_spec.rb
Outdated
Show resolved
Hide resolved
groyoh
approved these changes
Nov 24, 2025
app/services/billing_entities/update_invoice_issuing_date_settings_service.rb
Outdated
Show resolved
Hide resolved
julienbourdeau
approved these changes
Nov 26, 2025
f9ff7a2 to
aa9c06f
Compare
…_date (#4667) 👉 [Spec](https://www.notion.so/getlago/Spec-Define-the-issuing-date-preferences-of-subscription-invoices-2a0ef63110d2807d860cc22ced334bfb) 👉 [Dive In](https://www.notion.so/getlago/BE-Dive-In-Define-the-issuing-date-preferences-of-subscription-invoices-2a3ef63110d2800e8620fb5687f0edf9?d=2a3ef63110d2808f96fd001cbc71298b#2a3ef63110d2807abf14f498b984ac57) This PR is part of the Invoice Issuing Date preferences updates. With the new issuing date adjustment setting, `issuing_date` might skip using `invoice_grace_period` (when the adjustment set to "keep_anchor"). But we still need to factor in `invoice_grace_period` when finalizing invoices. This PR adds a new field, `expected_finalization_date`, which stores the date when a draft invoice should be auto-finalized. It's basically: ``` expected_finalization_date = invoice creation date + invoice_grace_period.days ``` The `expected_finalization_date` field is mostly for internal use. We only expose it in GraphQL so we can show the right message about when a draft invoice will be finalized. It's not available in the REST API or in the SDK clients.
0a00f8c to
917afaf
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Roadmap Task
👉 Spec
👉 Dive In
Context
This PR is part of the Invoice Issuing Date preferences updates.
Description
This PR implements the logic for
subscription_invoice_issuing_date_anchorandsubscription_invoice_issuing_date_adjustment. These settings only apply to recurring invoices – meaning invoices with type = "subscription" and invoicing_reason = "subscription_periodic". They don't affect invoices created when a subscription starts or terminated, or any other invoice types.Basic idea
subscription_invoice_issuing_date_anchorcan be eithercurrent_period_endornext_period_startsubscription_invoice_issuing_date_adjustmentcan be eitheralign_with_finalizationorkeep_anchorBilling period: from – to
The extra + 1.day in cases 1 and 3 matches how grace periods currently behave.
Example
Billing period: Oct 1 – Oct 31, 2025
Grace period: 3 days
Notes
Right now, invoices are actually generated on the first day of the next billing period, so the code is based on
to + 1.dayinstead of justto. The implementation is adjusted to match this behavior.Invoice::IssuingDateServiceInvoices::IssuingDateServicereturns an "adjustment" for the issuing date, which it calculates using all three issuing date settings (anchor, adjustment, and grace period). It can take both customer and billing entity as objects or hashes. We use the object version when calculating adjustments for new invoices, and the hash version when updating settings on the customer or billing entity, so we can still calculate adjustments using the old values.For the
current_period_end + align_with_finalization_datesetup: if the grace period is 0, we need to fall back to the actual end date of the current period – that’s why we do -1 in that case.Other changes
Renamed and updated all the
UpdateInvoiceGracePeriodFromBillingEntity-style services and jobs toUpdateInvoiceIssuingDateFromBillingEntity, so they now update the issuing date based on all the settings, not just the grace period.