Update ft_billing DAO functions to use postage

* Updated the 'fetch_billing_data_for_day' DAO function to take postage into
account
* Updated the 'update_fact_billing' DAO function to insert postage for
new rows. When updating rows which are identical apart from the postage, the
original row will be kept. (This behaviour will change once postage is
added to the primary key - at this point, upserting will add a new row.)
* Also changed some fixtures / test set up functions to take postage
into account
This commit is contained in:
Katie Smith
2018-09-26 11:28:59 +01:00
parent 0b5da2b8ad
commit 6727f0e0f5
6 changed files with 95 additions and 14 deletions

View File

@@ -169,6 +169,7 @@ def fetch_billing_data_for_day(process_day, service_id=None):
func.sum(table.billable_units).label('billable_units'),
func.count().label('notifications_sent'),
Service.crown,
func.coalesce(table.postage, 'none').label('postage')
).filter(
table.status.in_(NOTIFICATION_STATUS_TYPES_BILLABLE),
table.key_type != KEY_TYPE_TEST,
@@ -182,7 +183,8 @@ def fetch_billing_data_for_day(process_day, service_id=None):
'letter_page_count',
table.rate_multiplier,
table.international,
Service.crown
Service.crown,
table.postage,
).join(
Service
)
@@ -254,7 +256,8 @@ def update_fact_billing(data, process_day):
international=billing_record.international,
billable_units=billing_record.billable_units,
notifications_sent=billing_record.notifications_sent,
rate=billing_record.rate
rate=billing_record.rate,
postage=billing_record.postage,
)
stmt = stmt.on_conflict_do_update(
@@ -279,6 +282,7 @@ def create_billing_record(data, rate, process_day):
international=data.international,
billable_units=data.billable_units,
notifications_sent=data.notifications_sent,
rate=rate
rate=rate,
postage=data.postage,
)
return billing_record