[IMP] subscription_oca: track invoice periods on move lines#1441
Open
alvaro-domatix wants to merge 1 commit into
Open
[IMP] subscription_oca: track invoice periods on move lines#1441alvaro-domatix wants to merge 1 commit into
alvaro-domatix wants to merge 1 commit into
Conversation
3eedf94 to
ab01cf2
Compare
Invoice lines created from a subscription do not say which billing period
they cover and have no link back to the originating subscription, which
makes it hard for accounting to read invoices or to query revenue by
subscription.
This change adds three new fields on account.move.line:
* subscription_id: link to the originating sale.subscription.
* subscription_period_start / subscription_period_end: dates of the
period billed on this line.
A new helper sale.subscription._get_invoice_period returns the
(period_start, period_end) tuple for the current recurring cycle:
start = recurring_next_date, end = start + recurrence - 1 day.
sale.subscription.line._prepare_account_move_line accepts optional
period_start and period_end kwargs. When they are provided, both fields
are populated and the line description is enriched with the period
formatted in the partner's language ("Product (01/05/2026 - 31/05/2026)").
sale.subscription.create_invoice computes the period once and passes it
to every line, so manual_invoice, generate_invoice and the cron all
benefit without further changes.
ab01cf2 to
61b0272
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
Invoice lines created from a subscription do not say which billing period they cover and have no link back to the originating subscription. Accounting cannot tell at a glance which month an invoice line bills, and there is no easy way to query revenue by subscription.
Solution
Add three new fields on
account.move.line:subscription_id: link to the originatingsale.subscription(indexed,ondelete='set null').subscription_period_start/subscription_period_end: dates of the period billed on this line.A new helper
sale.subscription._get_invoice_period()returns the(period_start, period_end)tuple for the current recurring cycle:start = recurring_next_date,end = start + recurrence - 1 day.sale.subscription.line._prepare_account_move_linenow accepts optionalperiod_startandperiod_endkwargs. When they are provided, both fields are populated and the line description is enriched with the period formatted in the partner's language (e.g."Product (01/05/2026 - 31/05/2026)").sale.subscription.create_invoicecomputes the period once and passes it to every line, somanual_invoice,generate_invoiceand the cron all benefit without further changes.How to test
Run:
The new
tests/test_subscription_invoice_period.pycovers:_get_invoice_period()returns the expected(start, end)pair for a monthly template.create_invoice(), every generated move line has the matchingsubscription_id,subscription_period_startandsubscription_period_end." - "separator.