mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
[WIP]
Fix the query to count rather than sum the billing units. Need to fix the query that returns the monhtly billing, there is only one row but there should be two if there are two rates.
This commit is contained in:
@@ -30,8 +30,8 @@ def get_service_ids_that_need_billing_populated(start_date, end_date):
|
||||
@statsd(namespace="dao")
|
||||
def create_or_update_monthly_billing(service_id, billing_month):
|
||||
start_date, end_date = get_month_start_and_end_date_in_utc(billing_month)
|
||||
_update_monthly_billing(service_id, start_date, end_date, SMS_TYPE)
|
||||
_update_monthly_billing(service_id, start_date, end_date, EMAIL_TYPE)
|
||||
# _update_monthly_billing(service_id, start_date, end_date, SMS_TYPE)
|
||||
# _update_monthly_billing(service_id, start_date, end_date, EMAIL_TYPE)
|
||||
_update_monthly_billing(service_id, start_date, end_date, LETTER_TYPE)
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ def get_monthly_billing_by_notification_type(service_id, billing_month, notifica
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def get_billing_data_for_financial_year(service_id, year, notification_types=[SMS_TYPE, EMAIL_TYPE]):
|
||||
def get_billing_data_for_financial_year(service_id, year, notification_types=[SMS_TYPE, EMAIL_TYPE, LETTER_TYPE]):
|
||||
# Update totals to the latest so we include data for today
|
||||
now = convert_utc_to_bst(datetime.utcnow())
|
||||
create_or_update_monthly_billing(service_id=service_id, billing_month=now)
|
||||
|
||||
@@ -134,9 +134,8 @@ def billing_data_per_month_query(rate, service_id, start_date, end_date, notific
|
||||
).order_by(
|
||||
month,
|
||||
rate_multiplier()
|
||||
).all()
|
||||
|
||||
return results
|
||||
)
|
||||
return results.all()
|
||||
|
||||
|
||||
def rate_multiplier():
|
||||
@@ -152,7 +151,7 @@ def billing_letter_data_per_month_query(service_id, start_date, end_date):
|
||||
crown = Service.query.get(service_id).crown
|
||||
results = db.session.query(
|
||||
month.label('month'),
|
||||
func.sum(NotificationHistory.billable_units).label('billing_units'),
|
||||
func.count(NotificationHistory.billable_units).label('billing_units'),
|
||||
rate_multiplier().label('rate_multiplier'),
|
||||
NotificationHistory.international,
|
||||
NotificationHistory.notification_type,
|
||||
@@ -172,6 +171,5 @@ def billing_letter_data_per_month_query(service_id, start_date, end_date):
|
||||
).order_by(
|
||||
month,
|
||||
rate_multiplier()
|
||||
).all()
|
||||
|
||||
return results
|
||||
)
|
||||
return results.all()
|
||||
|
||||
Reference in New Issue
Block a user