fix(usage): count whole years when resolving the billing period - #8513
talissoncosta wants to merge 6 commits into
Conversation
The usage page cannot show which period someone is in or when their allowance resets. The term dates are on the subscription information cache but reach no response. Adds current_billing_period to the subscription, null outside an active term. A term can run longer than a month, so the window opens at the most recent monthly anniversary of its start. Contributes to #8257 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Counting the end from the period start loses the original day when a month is too short for it, so a term starting on the 31st produced a window that could end before today. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
relativedelta(...).months returns the month component alone, so a term that began over a year ago resolved to the same month a year early. A term starting September 2024 viewed today opened the current period in September 2025, which is the date range reported in #6099. The arithmetic was repeated at four call sites and wrong at two. It now lives in one place. Closes #6099 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Docker builds report
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## feat/current-billing-period-8257 #8513 +/- ##
=================================================================
Coverage 98.82% 98.82%
=================================================================
Files 1622 1624 +2
Lines 66771 66797 +26
=================================================================
+ Hits 65986 66012 +26
Misses 785 785 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
✅ private-cloud · depot-ubuntu-latest-16 — run #20410 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
🗂️ Previous results✅ oss · depot-ubuntu-latest-16 — run #20410 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-16)Details
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20410 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
✅ oss · depot-ubuntu-latest-arm-16 — run #20410 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
|
Visual Regression19 screenshots compared. See report for details. |
2f5bf0f to
f111a47
Compare
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
Closes #6099
relativedelta(now, starts_at).monthsreturns the month component on its own, so a billing term that began over a year ago resolved to the same month a year early. A term starting September 2024, viewed today, opened the current period in September 2025 — the date range in the issue.The arithmetic was repeated at four call sites and wrong at two:
analytics_db_servicecurrent periodorganisations/viewsnotification windowanalytics_db_serviceprevious periodtask_helpers._get_total_monthsAll four now use
organisations/billing_periods.py.models.current_billing_period()uses it too, so there is one definition rather than five.The previous-period branch counts both ends from the term start rather than deriving the end from the start:
period_start - 1 monthwould put a 31 January term on 28 January.Stacked on #8501, which adds the model method this shares. Base it on
mainonce that merges.How did you test this code?
test_unit_organisations_billing_periods.pycovers the helper, including a two-year span and a 31 January term in February.Regression tests at both fixed call sites, each using a term starting August 2025 viewed September 2026: the analytics period resolves to 2026, and the notification window no longer sweeps in a notification from twelve months earlier.