mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 00:41:35 -05:00
Add join to LetterRates for the billing query.
Fix the yearly totals to work for letters.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from sqlalchemy import Float, Integer
|
||||
from sqlalchemy import Float, Integer, and_
|
||||
from sqlalchemy import func, case, cast
|
||||
from sqlalchemy import literal_column
|
||||
|
||||
@@ -156,12 +156,18 @@ def billing_letter_data_per_month_query(service_id, start_date, end_date):
|
||||
NotificationHistory.international,
|
||||
NotificationHistory.notification_type,
|
||||
cast(LetterRate.rate, Float()).label('rate')
|
||||
).join(
|
||||
LetterRate,
|
||||
and_(NotificationHistory.created_at >= LetterRate.start_date,
|
||||
(LetterRate.end_date == None) | # noqa
|
||||
(LetterRate.end_date > NotificationHistory.created_at))
|
||||
).filter(
|
||||
*billing_data_filter(LETTER_TYPE, start_date, end_date, service_id),
|
||||
LetterRate.sheet_count == NotificationHistory.billable_units,
|
||||
LetterRate.crown == crown,
|
||||
NotificationHistory.created_at.between(LetterRate.start_date, end_date),
|
||||
LetterRate.post_class == 'second'
|
||||
LetterRate.post_class == 'second',
|
||||
NotificationHistory.created_at < end_date,
|
||||
|
||||
).group_by(
|
||||
NotificationHistory.notification_type,
|
||||
month,
|
||||
|
||||
Reference in New Issue
Block a user