[IMP] subscription_oca: centralize recurring date computation#1440
Open
alvaro-domatix wants to merge 1 commit into
Open
[IMP] subscription_oca: centralize recurring date computation#1440alvaro-domatix wants to merge 1 commit into
alvaro-domatix wants to merge 1 commit into
Conversation
The recurring_next_date logic was duplicated across onchange, write, create, generate_invoice, manual_invoice and the cron, with the increment based on the recurring_next_date stored in the record rather than on the date that was actually invoiced. This made changes hard to review and easy to break. Add five small, side-effect-free helpers on sale.subscription: * _get_recurrence_delta: relativedelta for the template recurrence (days/weeks/months/years), honoring recurring_interval. * _get_first_invoice_date: date_start when set, otherwise today. * _get_next_invoice_date(previous_date): previous_date + delta, with datetime/string normalization. * _set_next_invoice_date_after_invoice(invoice_date=None): advances recurring_next_date from the date that was actually invoiced. * _get_contract_end_date: end date derived from the template, or False when the template is unlimited. generate_invoice, manual_invoice and calculate_recurring_next_date are updated to use these helpers. The external behavior of the model is preserved: existing tests continue to pass and the new test module covers the helpers in isolation.
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
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.
Problem
The logic for
recurring_next_dateis scattered acrossonchange,write,create,generate_invoice,manual_invoiceand the cron, with the increment based on the value stored in the record rather than on the date that was actually invoiced. This dispersion makes the behavior hard to review and easy to break, especially when reasoning about contract end dates and first-invoice dates.Solution
Add five small, side-effect-free helpers on
sale.subscription:_get_recurrence_delta():relativedeltafor the template recurrence (days/weeks/months/years), honoringrecurring_interval._get_first_invoice_date():date_startwhen set, otherwise today._get_next_invoice_date(previous_date):previous_date + delta, with datetime/string normalization._set_next_invoice_date_after_invoice(invoice_date=None): advancesrecurring_next_datefrom the date that was actually invoiced._get_contract_end_date(): end date derived from the template, orFalsewhen the template is unlimited.generate_invoice,manual_invoiceandcalculate_recurring_next_dateare updated to use these helpers. The external behavior of the model is preserved: existing tests continue to pass and the new test module covers the helpers in isolation.How to test
Run:
The new
tests/test_subscription_recurrence_dates.pycovers:recurring_interval > 1.date_startwhen set._set_next_invoice_date_after_invoiceadvancesrecurring_next_dateby one recurrence unit.Falsefor unlimited templates anddate_start + durationfor limited ones.