mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 16:01:15 -05:00
Allow filtering of billing info by financial year
We already filter the usage-by-month query by financial year. When we show the total usage for a service, we should be able to filter this by financial year. Then, when the two lots of data are put side by side, it all adds up.
This commit is contained in:
@@ -8,15 +8,21 @@ from app.models import (
|
||||
NOTIFICATION_STATUS_TYPES_BILLABLE,
|
||||
KEY_TYPE_TEST
|
||||
)
|
||||
from app.dao.notifications_dao import get_financial_year
|
||||
|
||||
|
||||
def get_fragment_count(service_id):
|
||||
def get_fragment_count(service_id, year=None):
|
||||
shared_filters = [
|
||||
NotificationHistory.service_id == service_id,
|
||||
NotificationHistory.status.in_(NOTIFICATION_STATUS_TYPES_BILLABLE),
|
||||
NotificationHistory.key_type != KEY_TYPE_TEST
|
||||
]
|
||||
|
||||
if year:
|
||||
shared_filters.append(NotificationHistory.created_at.between(
|
||||
*get_financial_year(year)
|
||||
))
|
||||
|
||||
sms_count = db.session.query(
|
||||
func.sum(NotificationHistory.billable_units)
|
||||
).filter(
|
||||
|
||||
Reference in New Issue
Block a user