Remove the delete query when updating the ft_billing. It's in the wrong place and we also should not need it.

This commit is contained in:
Rebecca Law
2019-07-18 16:24:06 +01:00
parent ed611f982c
commit a52c65ea29
2 changed files with 15 additions and 10 deletions

View File

@@ -159,7 +159,7 @@ def fetch_billing_data_for_day(process_day, service_id=None):
notification_type=notification_type,
start_date=start_date,
end_date=end_date,
service_id = id_of_service
service_id=id_of_service
)
# If data has been purged from Notification then use NotificationHistory
if len(results) == 0:
@@ -285,10 +285,6 @@ def update_fact_billing(data, process_day):
data.postage)
billing_record = create_billing_record(data, rate, process_day)
FactBilling.query.filter(
FactBilling.bst_date == process_day
).delete()
table = FactBilling.__table__
'''
This uses the Postgres upsert to avoid race conditions when two threads try to insert

View File

@@ -38,13 +38,22 @@ def fetch_notification_status_for_day(process_day):
# if no rows try notificationHistory
for service_id in service_ids:
for notification_type in [EMAIL_TYPE, SMS_TYPE, LETTER_TYPE]:
table = Notification
data_for_service_and_type = query_for_fact_status_data(table, start_date, end_date, notification_type, service_id)
data_for_service_and_type = query_for_fact_status_data(
table=Notification,
start_date=start_date,
end_date=end_date,
notification_type=notification_type,
service_id=service_id
)
if len(data_for_service_and_type) == 0:
table = NotificationHistory
data_for_service_and_type = query_for_fact_status_data(table, start_date, end_date, notification_type, service_id)
data_for_service_and_type = query_for_fact_status_data(
table=NotificationHistory,
start_date=start_date,
end_date=end_date,
notification_type=notification_type,
service_id=service_id
)
all_data_for_process_day = all_data_for_process_day + data_for_service_and_type
return all_data_for_process_day