mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
Use table class directly instead of "table" var
In response to [^1]. [^1]: https://github.com/alphagov/notifications-api/pull/3546#discussion_r879541366
This commit is contained in:
@@ -467,11 +467,9 @@ def fetch_billing_data_for_day(process_day, service_id=None, check_permissions=F
|
||||
|
||||
|
||||
def _query_for_billing_data(notification_type, start_date, end_date, service):
|
||||
table = NotificationAllTimeView
|
||||
|
||||
def _email_query():
|
||||
return db.session.query(
|
||||
table.template_id,
|
||||
NotificationAllTimeView.template_id,
|
||||
literal(service.crown).label('crown'),
|
||||
literal(service.id).label('service_id'),
|
||||
literal(notification_type).label('notification_type'),
|
||||
@@ -483,22 +481,22 @@ def _query_for_billing_data(notification_type, start_date, end_date, service):
|
||||
literal(0).label('billable_units'),
|
||||
func.count().label('notifications_sent'),
|
||||
).filter(
|
||||
table.status.in_(NOTIFICATION_STATUS_TYPES_SENT_EMAILS),
|
||||
table.key_type.in_((KEY_TYPE_NORMAL, KEY_TYPE_TEAM)),
|
||||
table.created_at >= start_date,
|
||||
table.created_at < end_date,
|
||||
table.notification_type == notification_type,
|
||||
table.service_id == service.id
|
||||
NotificationAllTimeView.status.in_(NOTIFICATION_STATUS_TYPES_SENT_EMAILS),
|
||||
NotificationAllTimeView.key_type.in_((KEY_TYPE_NORMAL, KEY_TYPE_TEAM)),
|
||||
NotificationAllTimeView.created_at >= start_date,
|
||||
NotificationAllTimeView.created_at < end_date,
|
||||
NotificationAllTimeView.notification_type == notification_type,
|
||||
NotificationAllTimeView.service_id == service.id
|
||||
).group_by(
|
||||
table.template_id,
|
||||
NotificationAllTimeView.template_id,
|
||||
)
|
||||
|
||||
def _sms_query():
|
||||
sent_by = func.coalesce(table.sent_by, 'unknown')
|
||||
rate_multiplier = func.coalesce(table.rate_multiplier, 1).cast(Integer)
|
||||
international = func.coalesce(table.international, False)
|
||||
sent_by = func.coalesce(NotificationAllTimeView.sent_by, 'unknown')
|
||||
rate_multiplier = func.coalesce(NotificationAllTimeView.rate_multiplier, 1).cast(Integer)
|
||||
international = func.coalesce(NotificationAllTimeView.international, False)
|
||||
return db.session.query(
|
||||
table.template_id,
|
||||
NotificationAllTimeView.template_id,
|
||||
literal(service.crown).label('crown'),
|
||||
literal(service.id).label('service_id'),
|
||||
literal(notification_type).label('notification_type'),
|
||||
@@ -507,50 +505,50 @@ def _query_for_billing_data(notification_type, start_date, end_date, service):
|
||||
international.label('international'),
|
||||
literal(None).label('letter_page_count'),
|
||||
literal('none').label('postage'),
|
||||
func.sum(table.billable_units).label('billable_units'),
|
||||
func.sum(NotificationAllTimeView.billable_units).label('billable_units'),
|
||||
func.count().label('notifications_sent'),
|
||||
).filter(
|
||||
table.status.in_(NOTIFICATION_STATUS_TYPES_BILLABLE_SMS),
|
||||
table.key_type.in_((KEY_TYPE_NORMAL, KEY_TYPE_TEAM)),
|
||||
table.created_at >= start_date,
|
||||
table.created_at < end_date,
|
||||
table.notification_type == notification_type,
|
||||
table.service_id == service.id
|
||||
NotificationAllTimeView.status.in_(NOTIFICATION_STATUS_TYPES_BILLABLE_SMS),
|
||||
NotificationAllTimeView.key_type.in_((KEY_TYPE_NORMAL, KEY_TYPE_TEAM)),
|
||||
NotificationAllTimeView.created_at >= start_date,
|
||||
NotificationAllTimeView.created_at < end_date,
|
||||
NotificationAllTimeView.notification_type == notification_type,
|
||||
NotificationAllTimeView.service_id == service.id
|
||||
).group_by(
|
||||
table.template_id,
|
||||
NotificationAllTimeView.template_id,
|
||||
sent_by,
|
||||
rate_multiplier,
|
||||
international,
|
||||
)
|
||||
|
||||
def _letter_query():
|
||||
rate_multiplier = func.coalesce(table.rate_multiplier, 1).cast(Integer)
|
||||
postage = func.coalesce(table.postage, 'none')
|
||||
rate_multiplier = func.coalesce(NotificationAllTimeView.rate_multiplier, 1).cast(Integer)
|
||||
postage = func.coalesce(NotificationAllTimeView.postage, 'none')
|
||||
return db.session.query(
|
||||
table.template_id,
|
||||
NotificationAllTimeView.template_id,
|
||||
literal(service.crown).label('crown'),
|
||||
literal(service.id).label('service_id'),
|
||||
literal(notification_type).label('notification_type'),
|
||||
literal('dvla').label('sent_by'),
|
||||
rate_multiplier.label('rate_multiplier'),
|
||||
table.international,
|
||||
table.billable_units.label('letter_page_count'),
|
||||
NotificationAllTimeView.international,
|
||||
NotificationAllTimeView.billable_units.label('letter_page_count'),
|
||||
postage.label('postage'),
|
||||
func.sum(table.billable_units).label('billable_units'),
|
||||
func.sum(NotificationAllTimeView.billable_units).label('billable_units'),
|
||||
func.count().label('notifications_sent'),
|
||||
).filter(
|
||||
table.status.in_(NOTIFICATION_STATUS_TYPES_BILLABLE_FOR_LETTERS),
|
||||
table.key_type.in_((KEY_TYPE_NORMAL, KEY_TYPE_TEAM)),
|
||||
table.created_at >= start_date,
|
||||
table.created_at < end_date,
|
||||
table.notification_type == notification_type,
|
||||
table.service_id == service.id
|
||||
NotificationAllTimeView.status.in_(NOTIFICATION_STATUS_TYPES_BILLABLE_FOR_LETTERS),
|
||||
NotificationAllTimeView.key_type.in_((KEY_TYPE_NORMAL, KEY_TYPE_TEAM)),
|
||||
NotificationAllTimeView.created_at >= start_date,
|
||||
NotificationAllTimeView.created_at < end_date,
|
||||
NotificationAllTimeView.notification_type == notification_type,
|
||||
NotificationAllTimeView.service_id == service.id
|
||||
).group_by(
|
||||
table.template_id,
|
||||
NotificationAllTimeView.template_id,
|
||||
rate_multiplier,
|
||||
table.billable_units,
|
||||
NotificationAllTimeView.billable_units,
|
||||
postage,
|
||||
table.international
|
||||
NotificationAllTimeView.international
|
||||
)
|
||||
|
||||
query_funcs = {
|
||||
|
||||
Reference in New Issue
Block a user