Added command to populate data for annual billing based on last years values.

This commit is contained in:
Rebecca Law
2019-08-23 17:02:44 +01:00
committed by Leo Hemsted
parent cb7fff6100
commit 1c94d6d24a
5 changed files with 88 additions and 33 deletions

View File

@@ -34,6 +34,7 @@ from app.utils import get_london_midnight_in_utc
def fetch_sms_free_allowance_remainder(start_date):
# ASSUMPTION: AnnualBilling has been populated for year.
billing_year = which_financial_year(start_date)
print(billing_year)
start_of_year = convert_utc_to_bst(financial_year_start(billing_year))
query = db.session.query(
FactBilling.service_id.label("service_id"),
@@ -62,7 +63,7 @@ def fetch_sms_billing_for_all_services(start_date, end_date):
billing_year = which_financial_year(start_date)
free_allowance_remainder = fetch_sms_free_allowance_remainder(start_date).subquery()
sms_billable_units = func.sum(FactBilling.billable_units * FactBilling.rate_multiplier)
sms_remainder = func.coalesce(free_allowance_remainder.c.sms_remainder, 0)
sms_remainder = func.coalesce(free_allowance_remainder.c.sms_remainder, AnnualBilling.free_sms_fragment_limit)
chargeable_sms = case([(sms_remainder == 0, sms_billable_units),
(sms_billable_units - sms_remainder <= 0, 0),
(sms_billable_units - sms_remainder > 0,