[IMP] subscription_oca: compute MRR and ARR#1443
Closed
alvaro-domatix wants to merge 1 commit into
Closed
Conversation
Add two stored computed monetary fields on `sale.subscription`: * `recurring_monthly` — sum of the subscription lines normalised to a monthly amount (Monthly Recurring Revenue). * `recurring_yearly` — twelve times the monthly figure (Annual Recurring Revenue). Each line also exposes its own `recurring_monthly`, derived from `price_subtotal` and the template recurrence. A line that bills every N `days`, `weeks`, `months` or `years` is converted to months using 30.4375 average days per month for sub-monthly cadences and a direct multiplier otherwise, then divided by the `recurring_interval`. This makes subscriptions of different cadences directly comparable and sum-able, so reports can answer the basic "how much do I bill per month?" question without external spreadsheets. The fields are visible as a new MRR/ARR stat button on the subscription form, as optional columns with sum aggregation on the list view, and as a "With recurring revenue" filter on the search view. Migration: pure ORM recompute on `-u subscription_oca`. Expect roughly two seconds per ten thousand subscription lines.
25e1ba6 to
6a3da2d
Compare
Author
|
Closing to keep iterating locally; will resubmit when ready. |
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
sale.subscription.recurring_totalis the sum of the lineprice_subtotalwithout normalising to a single cadence. A yearly subscription that bills 1 200 € once a year and a monthly one that bills 100 € a month look very different in the list view even though they generate identical recurring revenue. Aggregating across cadences is impossible — the basic management question "how much do I bill per month?" can only be answered by exporting to a spreadsheet and dividing case by case.Solution
Add two new stored computed monetary fields on
sale.subscription:recurring_monthly— monthly recurring revenue (MRR), summed from a per-linerecurring_monthly.recurring_yearly— twelve times the monthly figure (ARR).The line-level
recurring_monthlydividesprice_subtotalby the number of months in the line's period. The factor is1 / 30.4375for days,7 / 30.4375for weeks,1.0for months and12.0for years, multiplied byrecurring_interval. So a 100 €/week line yields ≈ 434.82 €/month, a 1 200 €/year line yields 100 €/month, a 300 € line every 3 months yields 100 €/month.UI changes:
recurring_monthly(sumfooter, optionalshow) andrecurring_yearly(optionalhide).recurring_monthly > 0).No existing field is renamed, dropped or otherwise altered (see §0.4 of the internal compatibility checklist). Pure additive change.
Migration
-u subscription_ocatriggers a normal ORM recompute. No data script. Estimate roughly two seconds per ten thousand subscription lines on commodity hardware.How to test
recurring_rule_type = months,recurring_interval = 1. Add a subscription line with a 100 € product →recurring_monthly = 100,recurring_yearly = 1200.years→recurring_monthly = 100 / 12 ≈ 8.33.weeks, interval 1 →recurring_monthly = 100 * 30.4375 / 7 ≈ 434.82.months, interval 3 →recurring_monthly = 100 / 3 ≈ 33.33.The bundled tests in
tests/test_subscription_mrr.pycover all of the above plus aggregation across lines and recompute after qty or template changes.