diff --git a/app/celery/reporting_tasks.py b/app/celery/reporting_tasks.py index f9c336638..607fad160 100644 --- a/app/celery/reporting_tasks.py +++ b/app/celery/reporting_tasks.py @@ -1,5 +1,6 @@ from datetime import datetime, timedelta +from flask import current_app from notifications_utils.statsd_decorators import statsd from app import notify_celery @@ -24,3 +25,5 @@ def create_nightly_billing(day_start=None): for data in transit_data: update_fact_billing(data, process_day) + + current_app.logger.info("create-nightly-billing task complete. {} rows updated".format(len(transit_data))) diff --git a/app/dao/fact_billing_dao.py b/app/dao/fact_billing_dao.py index f69df16f3..fc8ebd044 100644 --- a/app/dao/fact_billing_dao.py +++ b/app/dao/fact_billing_dao.py @@ -1,6 +1,5 @@ from datetime import datetime, timedelta, time -from flask import current_app from sqlalchemy import func, case, desc, Date from app import db @@ -97,6 +96,7 @@ def fetch_billing_data_for_day(process_day, service_id=None): ) if service_id: transit_data = transit_data.filter(Notification.service_id == service_id) + return transit_data.all() @@ -121,7 +121,6 @@ def update_fact_billing(data, process_day): inserted_records = 0 updated_records = 0 non_letter_rates, letter_rates = get_rates_for_billing() - print("process_day: {} {}".format(type(process_day), process_day)) update_count = FactBilling.query.filter( FactBilling.bst_date == datetime.date(process_day), FactBilling.template_id == data.template_id, @@ -147,8 +146,6 @@ def update_fact_billing(data, process_day): inserted_records += 1 updated_records += update_count db.session.commit() - current_app.logger.info('ft_billing for {}: {} rows updated, {} rows inserted' - .format(process_day, updated_records, inserted_records)) def create_billing_record(data, rate, process_day): diff --git a/app/models.py b/app/models.py index 547c0a0d9..9d7591e28 100644 --- a/app/models.py +++ b/app/models.py @@ -1784,10 +1784,10 @@ class FactBilling(db.Model): service_id = db.Column(UUID(as_uuid=True), nullable=False, index=True) notification_type = db.Column(db.Text, nullable=False, primary_key=True) provider = db.Column(db.Text, nullable=True, primary_key=True) - rate_multiplier = db.Column(db.Numeric(), nullable=True, primary_key=True) + rate_multiplier = db.Column(db.Integer(), nullable=True, primary_key=True) international = db.Column(db.Boolean, nullable=False, primary_key=False) rate = db.Column(db.Numeric(), nullable=True) - billable_units = db.Column(db.Numeric(), nullable=True) + billable_units = db.Column(db.Integer(), nullable=True) notifications_sent = db.Column(db.Integer(), nullable=True) diff --git a/tests/app/dao/test_ft_billing_dao.py b/tests/app/dao/test_ft_billing_dao.py index 216caa447..f6df9e4bd 100644 --- a/tests/app/dao/test_ft_billing_dao.py +++ b/tests/app/dao/test_ft_billing_dao.py @@ -7,7 +7,7 @@ from freezegun import freeze_time from app import db from app.dao.fact_billing_dao import ( fetch_monthly_billing_for_year, fetch_billing_data_for_day, get_rates_for_billing, - get_rate + get_rate, ) from app.models import FactBilling from app.utils import convert_utc_to_bst