mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Change get_financial_year to return ending date as 1 microsecond earlier.
That way we can write the queries as between start and end dates, making it easier to read. This makes more sense.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import pytz
|
||||
|
||||
|
||||
def get_financial_year(year):
|
||||
return get_april_fools(year), get_april_fools(year + 1)
|
||||
return get_april_fools(year), get_april_fools(year + 1) - timedelta(microseconds=1)
|
||||
|
||||
|
||||
def get_april_fools(year):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Float, Integer
|
||||
from sqlalchemy import func, case, cast, desc, between
|
||||
from sqlalchemy import func, case, cast
|
||||
from sqlalchemy import literal_column
|
||||
|
||||
from app import db
|
||||
@@ -49,8 +49,7 @@ def get_monthly_billing_data(service_id, year):
|
||||
def billing_data_filter(notification_type, start_date, end_date, service_id):
|
||||
return [
|
||||
NotificationHistory.notification_type == notification_type,
|
||||
NotificationHistory.created_at >= start_date,
|
||||
NotificationHistory.created_at < end_date,
|
||||
NotificationHistory.created_at.between(start_date, end_date),
|
||||
NotificationHistory.service_id == service_id,
|
||||
NotificationHistory.status.in_(NOTIFICATION_STATUS_TYPES_BILLABLE),
|
||||
NotificationHistory.key_type != KEY_TYPE_TEST
|
||||
@@ -106,11 +105,11 @@ def get_rates_for_year(start_date, end_date, notification_type):
|
||||
rates = Rate.query.filter(Rate.notification_type == notification_type).order_by(Rate.valid_from).all()
|
||||
results = []
|
||||
for current_rate, current_rate_expiry_date in zip(rates, rates[1:]):
|
||||
if is_between_end_date_exclusive(current_rate.valid_from, start_date, end_date) or \
|
||||
is_between_end_date_exclusive(current_rate_expiry_date.valid_from, start_date, end_date):
|
||||
if is_between(current_rate.valid_from, start_date, end_date) or \
|
||||
is_between(current_rate_expiry_date.valid_from, start_date, end_date):
|
||||
results.append(current_rate)
|
||||
|
||||
if is_between_end_date_exclusive(rates[-1].valid_from, start_date, end_date):
|
||||
if is_between(rates[-1].valid_from, start_date, end_date):
|
||||
results.append(rates[-1])
|
||||
|
||||
if not results:
|
||||
@@ -120,8 +119,8 @@ def get_rates_for_year(start_date, end_date, notification_type):
|
||||
return results
|
||||
|
||||
|
||||
def is_between_end_date_exclusive(date, start_date, end_date):
|
||||
return start_date <= date < end_date
|
||||
def is_between(date, start_date, end_date):
|
||||
return start_date <= date <= end_date
|
||||
|
||||
|
||||
def sms_billing_data_per_month_query(rate, service_id, start_date, end_date):
|
||||
|
||||
@@ -250,8 +250,7 @@ def get_notification_billable_unit_count_per_month(service_id, year):
|
||||
).filter(
|
||||
NotificationHistory.billable_units != 0,
|
||||
NotificationHistory.service_id == service_id,
|
||||
NotificationHistory.created_at >= start_date,
|
||||
NotificationHistory.created_at < end_date
|
||||
NotificationHistory.created_at.between(start_date, end_date)
|
||||
).group_by(
|
||||
month
|
||||
).order_by(
|
||||
|
||||
@@ -237,8 +237,7 @@ def dao_fetch_monthly_historical_stats_by_template_for_service(service_id, year)
|
||||
func.count().label('count')
|
||||
).filter(
|
||||
NotificationHistory.service_id == service_id,
|
||||
NotificationHistory.created_at >= start_date,
|
||||
NotificationHistory.created_at < end_date
|
||||
NotificationHistory.created_at.between(start_date, end_date)
|
||||
|
||||
).group_by(
|
||||
month,
|
||||
@@ -273,8 +272,7 @@ def dao_fetch_monthly_historical_stats_for_service(service_id, year):
|
||||
func.count(NotificationHistory.id).label('count')
|
||||
).filter(
|
||||
NotificationHistory.service_id == service_id,
|
||||
NotificationHistory.created_at >= start_date,
|
||||
NotificationHistory.created_at < end_date
|
||||
NotificationHistory.created_at.between(start_date, end_date)
|
||||
).group_by(
|
||||
NotificationHistory.notification_type,
|
||||
NotificationHistory.status,
|
||||
|
||||
Reference in New Issue
Block a user