mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 15:15:38 -05:00
primary key for ft_billing should use notification_type
This commit is contained in:
@@ -13,6 +13,7 @@ from sqlalchemy import func, desc, case
|
||||
from app.dao.dao_utils import transactional
|
||||
from notifications_utils.statsd_decorators import statsd
|
||||
from app import notify_celery
|
||||
from flask import current_app
|
||||
|
||||
|
||||
def get_rate(non_letter_rates, letter_rates, notification_type, date, crown=None, rate_multiplier=None):
|
||||
@@ -76,13 +77,16 @@ def create_nightly_billing(day_start=None):
|
||||
'day_created'
|
||||
).all()
|
||||
|
||||
updated_records = 0
|
||||
inserted_records = 0
|
||||
|
||||
for data in transit_data:
|
||||
update_count = FactBilling.query.filter(
|
||||
FactBilling.bst_date == data.day_created,
|
||||
FactBilling.template_id == data.template_id,
|
||||
FactBilling.provider == data.sent_by, # This could be zero - this is a bug that needs to be fixed.
|
||||
FactBilling.rate_multiplier == data.rate_multiplier,
|
||||
FactBilling.international == data.international,
|
||||
FactBilling.notification_type == data.notification_type,
|
||||
).update(
|
||||
{"notifications_sent": data.notifications_sent,
|
||||
"billable_units": data.billable_units},
|
||||
@@ -106,3 +110,9 @@ def create_nightly_billing(day_start=None):
|
||||
data.rate_multiplier)
|
||||
)
|
||||
db.session.add(billing_record)
|
||||
inserted_records += 1
|
||||
|
||||
updated_records += update_count
|
||||
|
||||
current_app.logger.info('ft_billing: {} rows updated, {} rows inserted'
|
||||
.format(updated_records, inserted_records))
|
||||
|
||||
@@ -1774,10 +1774,10 @@ class FactBilling(db.Model):
|
||||
bst_date = db.Column(db.Date, nullable=False, primary_key=True, index=True)
|
||||
template_id = db.Column(UUID(as_uuid=True), nullable=False, primary_key=True, index=True)
|
||||
service_id = db.Column(UUID(as_uuid=True), nullable=False, index=True)
|
||||
notification_type = db.Column(db.Text, nullable=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)
|
||||
international = db.Column(db.Boolean, 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)
|
||||
notifications_sent = db.Column(db.Integer(), nullable=True)
|
||||
|
||||
Reference in New Issue
Block a user