[19.0][FIX] subscription_oca: avoid duplicated invoices per period#1473
Open
alvaro-domatix wants to merge 1 commit into
Open
[19.0][FIX] subscription_oca: avoid duplicated invoices per period#1473alvaro-domatix wants to merge 1 commit into
alvaro-domatix wants to merge 1 commit into
Conversation
af45e1d to
e0d565c
Compare
If the cron failed mid-batch and was relaunched, or if a user clicked the manual invoice action twice, the subscription happily produced two invoices for the same billing period. There was no defense against duplicates at the model level. This change adds two helpers on sale.subscription: * _get_existing_invoice_for_period(period_start, period_end): returns the first account.move whose lines link back to this subscription with the given period and whose state is not 'cancel'. Cancelled invoices do not block, since they can legitimately be re-issued. * _can_create_invoice_for_period(period_start, period_end): the boolean wrapper used by callers. manual_invoice raises a UserError with the formatted period when a blocking invoice exists, so the user can act on it. generate_invoice (called by the cron) logs a warning and returns False so the batch continues with the next subscription. The existing _collect_all_sub_test_results helper called create_invoice and manual_invoice in immediate succession on the same period, which under the new policy would mean creating duplicates. The fixture now advances recurring_next_date between the two calls so it tests the intended two-period workflow rather than the previously unprotected duplicate.
e0d565c to
7e8dd03
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.
Prevents a subscription from being invoiced twice for the same billing period.
If the recurring cron fails mid-batch and is relaunched, or if the manual invoice action is triggered again before the recurring date has advanced, the subscription otherwise produces two invoices for the same period. Two helpers are added on
sale.subscription:_get_existing_invoice_for_period(start, end)returns the first non-cancelled invoice whose lines link back to the subscription for that period (cancelled invoices do not block, since they can legitimately be re-issued);_can_create_invoice_for_period(start, end)is the boolean wrapper.manual_invoiceraises aUserErrorwith the formatted period when a blocking invoice exists;generate_invoice(cron path) logs a warning and returnsFalseso the batch continues with the next subscription. Invoicing the next period is intentionally left allowed — a second call after the recurring date has advanced bills the following cycle, which is not a duplicate.