[REF] subscription_oca: split subscription cron responsibilities#1442
Open
alvaro-domatix wants to merge 1 commit into
Open
[REF] subscription_oca: split subscription cron responsibilities#1442alvaro-domatix wants to merge 1 commit into
alvaro-domatix wants to merge 1 commit into
Conversation
cron_subscription_management used to walk every sale.subscription with self.search([]) and decide inside the loop whether to start, invoice or close each record. A single exception aborted the rest of the batch when the failure happened outside the inner try/except (e.g. while starting a subscription), and there was no way to cap the number of records processed in one run. Split the entry point into three small dedicated methods with restrictive domains, each guarded by per-record try/except: * _cron_start_due_subscriptions: activates draft/pre subscriptions whose date_start has passed and issues their first invoice. * _cron_invoice_due_subscriptions: invoices in-progress subscriptions whose recurring_next_date is due and that actually have lines. * _cron_close_ended_subscriptions: closes in-progress subscriptions whose end date has passed. cron_subscription_management keeps working as an entry point that calls all three in order, with a new optional limit argument forwarded to each. The external behavior of the cron is preserved: existing subscriptions get invoiced, started and closed exactly as before. The legacy cron error test used to assert UserError propagation, which only happened when the failure occurred in the unguarded start branch; with errors now logged per record across all three methods the cron finishes the batch and the test verifies the call rather than the exception.
67d61b2 to
ad8640a
Compare
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
cron_subscription_managementused to walk everysale.subscriptionwithself.search([])and decide inside the loop whether to start, invoice or close each record. A single exception aborted the rest of the batch when the failure happened outside the innertry/except(e.g. while starting a subscription), and there was no way to cap the number of records processed in one run.Solution
Split the entry point into three small dedicated methods with restrictive domains, each guarded by per-record
try/except:_cron_start_due_subscriptions: activates draft /presubscriptions whosedate_starthas passed and issues their first invoice._cron_invoice_due_subscriptions: invoices in-progress subscriptions whoserecurring_next_dateis due and that actually have lines._cron_close_ended_subscriptions: closes in-progress subscriptions whose end date has passed.cron_subscription_managementkeeps working as an entry point that calls all three in order, with a new optionallimitargument forwarded to each.The external behavior of the cron is preserved: existing subscriptions get invoiced, started and closed exactly as before. The only intentional change is that an exception in one record no longer aborts the rest of the batch.
How to test
Run:
The new
tests/test_subscription_cron.pycovers:recurring_next_dateis in the future.UserErrorraised by one subscription does not stop the batch — the next one is still invoiced.limitargument caps the number of records processed.The legacy
test_subscription_oca_sub_cron_errortest used to assertUserErrorpropagation, which only happened in the previously unguarded start branch; with errors now logged per record across all three methods the cron finishes the batch and the test verifies the call rather than the exception.