From 515b34c404b2070f28b128a29eba0bdda8f7a71b Mon Sep 17 00:00:00 2001 From: Zach Aysan Date: Thu, 30 May 2024 05:12:14 -0400 Subject: [PATCH] fix: Set billing starts at to reasonable default for API usage notifications (#4054) --- api/organisations/views.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/organisations/views.py b/api/organisations/views.py index 4c2e4c31f441..c5ccfd591ceb 100644 --- a/api/organisations/views.py +++ b/api/organisations/views.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import logging +from datetime import timedelta from app_analytics.influxdb_wrapper import ( get_events_for_organisation, @@ -324,6 +325,10 @@ def get_queryset(self): billing_starts_at = subscription_cache.current_billing_term_starts_at now = timezone.now() + # Handle case where billing dates are not set by + # defaulting to something as a reasonable default. + billing_starts_at = billing_starts_at or now - timedelta(days=30) + month_delta = relativedelta(now, billing_starts_at).months period_starts_at = relativedelta(months=month_delta) + billing_starts_at