mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 17:01:35 -05:00
Add and test new DAO method that counts the billable units multiplied by rate multiplier for a given service for a given time period.
Currently this is SMS only. Used by the dashboard for a headline figure.
This commit is contained in:
@@ -153,3 +153,21 @@ def rate_multiplier():
|
||||
(NotificationHistory.rate_multiplier == None, literal_column("'1'")), # noqa
|
||||
(NotificationHistory.rate_multiplier != None, NotificationHistory.rate_multiplier), # noqa
|
||||
]), Integer())
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def get_total_billable_units_for_sent_sms_notifications_in_date_range(start_date, end_date, service_id):
|
||||
result = db.session.query(
|
||||
func.sum(
|
||||
NotificationHistory.billable_units * func.coalesce(NotificationHistory.rate_multiplier, 1)
|
||||
).label('billable_units')
|
||||
).filter(
|
||||
NotificationHistory.service_id == service_id,
|
||||
NotificationHistory.notification_type == 'sms',
|
||||
NotificationHistory.created_at >= start_date,
|
||||
NotificationHistory.created_at <= end_date,
|
||||
NotificationHistory.status.in_(NOTIFICATION_STATUS_TYPES_BILLABLE)
|
||||
)
|
||||
if result.scalar():
|
||||
return int(result.scalar())
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user