notify-136 change financial year starting in april to calendar year (#278)

Co-authored-by: Kenneth Kehl <@kkehl@flexion.us>
This commit is contained in:
Kenneth Kehl
2023-06-14 13:19:11 -07:00
committed by GitHub
parent e9fccc8493
commit 9f9e0a6ad8
16 changed files with 96 additions and 97 deletions

View File

@@ -7,8 +7,8 @@ from sqlalchemy.sql.expression import case, literal
from app import db
from app.dao.date_util import (
get_financial_year_dates,
get_financial_year_for_datetime,
get_calendar_year_dates,
get_calendar_year_for_datetime,
)
from app.dao.organisation_dao import dao_get_organisation_live_services
from app.models import (
@@ -31,7 +31,7 @@ from app.utils import get_midnight_in_utc
def fetch_sms_free_allowance_remainder_until_date(end_date):
# ASSUMPTION: AnnualBilling has been populated for year.
billing_year = get_financial_year_for_datetime(end_date)
billing_year = get_calendar_year_for_datetime(end_date)
start_of_year = date(billing_year, 4, 1)
billable_units = func.coalesce(func.sum(FactBilling.billable_units * FactBilling.rate_multiplier), 0)
@@ -177,7 +177,7 @@ def fetch_monthly_billing_for_year(service_id, year):
Since the data in ft_billing is only refreshed once a day for all services,
we also update the table on-the-fly if we need accurate data for this year.
"""
_, year_end = get_financial_year_dates(year)
_, year_end = get_calendar_year_dates(year)
today = datetime.utcnow().date()
# if year end date is less than today, we are calculating for data in the past and have no need for deltas.
@@ -216,7 +216,7 @@ def fetch_monthly_billing_for_year(service_id, year):
def query_service_email_usage_for_year(service_id, year):
year_start, year_end = get_financial_year_dates(year)
year_start, year_end = get_calendar_year_dates(year)
return db.session.query(
FactBilling.local_date,
@@ -265,7 +265,7 @@ def query_service_sms_usage_for_year(service_id, year):
on a given local_date. This means we don't need to worry about how to assign
free allowance if it happens to run out when a rate changes.
"""
year_start, year_end = get_financial_year_dates(year)
year_start, year_end = get_calendar_year_dates(year)
this_rows_chargeable_units = FactBilling.billable_units * FactBilling.rate_multiplier
# Subquery for the number of chargeable units in all rows preceding this one,
@@ -568,7 +568,7 @@ def query_organisation_sms_usage_for_year(organisation_id, year):
"""
See docstring for query_service_sms_usage_for_year()
"""
year_start, year_end = get_financial_year_dates(year)
year_start, year_end = get_calendar_year_dates(year)
this_rows_chargeable_units = FactBilling.billable_units * FactBilling.rate_multiplier
# Subquery for the number of chargeable units in all rows preceding this one,
@@ -622,7 +622,7 @@ def query_organisation_sms_usage_for_year(organisation_id, year):
def fetch_usage_year_for_organisation(organisation_id, year):
year_start, year_end = get_financial_year_dates(year)
year_start, year_end = get_calendar_year_dates(year)
today = datetime.utcnow().date()
services = dao_get_organisation_live_services(organisation_id)