Skip to content

[IMP] subscription_oca: track invoice periods on move lines#1441

Open
alvaro-domatix wants to merge 1 commit into
OCA:19.0from
alvaro-domatix:19.0-imp-subscription_oca-invoice-period-tracking
Open

[IMP] subscription_oca: track invoice periods on move lines#1441
alvaro-domatix wants to merge 1 commit into
OCA:19.0from
alvaro-domatix:19.0-imp-subscription_oca-invoice-period-tracking

Conversation

@alvaro-domatix
Copy link
Copy Markdown

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 originating sale.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_line now 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 (e.g. "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.

How to test

Run:

odoo-bin -d <db> --init=subscription_oca --stop-after-init
odoo-bin -d <db> -u subscription_oca --test-enable --test-tags=/subscription_oca --stop-after-init

The new tests/test_subscription_invoice_period.py covers:

  • _get_invoice_period() returns the expected (start, end) pair for a monthly template.
  • After create_invoice(), every generated move line has the matching subscription_id, subscription_period_start and subscription_period_end.
  • Move line descriptions contain the period dates and the " - " separator.

@alvaro-domatix alvaro-domatix force-pushed the 19.0-imp-subscription_oca-invoice-period-tracking branch from 3eedf94 to ab01cf2 Compare May 27, 2026 14:50
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.
@alvaro-domatix alvaro-domatix force-pushed the 19.0-imp-subscription_oca-invoice-period-tracking branch from ab01cf2 to 61b0272 Compare May 27, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants