We found that the reporting task failed twice because of integrity constraints.

This was because the rate_multiplier was being added as 1 and 1.0 which was not resolving to the same.
This updates the table to use Integrer.
Also changed the logging for the task.
This commit is contained in:
Rebecca Law
2018-05-10 15:35:58 +01:00
parent d52e65d89a
commit 8028f6cc28
4 changed files with 7 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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