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:
Rebecca Law
2017-12-15 17:29:32 +00:00
parent c08f67ea63
commit e0e64d51d5
4 changed files with 25 additions and 18 deletions

View File

@@ -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)

View File

@@ -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()