mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
New endpoint to get monthly billing usage from the ft_billing table.
New command to compare the results of monthly billing to ft_billing.
This commit is contained in:
@@ -23,9 +23,9 @@ from app.utils import convert_utc_to_bst, convert_bst_to_utc
|
||||
def fetch_monthly_billing_for_year(service_id, year):
|
||||
year_start_date, year_end_date = get_financial_year(year)
|
||||
utcnow = datetime.utcnow()
|
||||
today = convert_utc_to_bst(utcnow).date()
|
||||
today = convert_utc_to_bst(utcnow)
|
||||
# if year end date is less than today, we are calculating for data in the past and have no need for deltas.
|
||||
if year_end_date.date() >= today:
|
||||
if year_end_date >= today:
|
||||
yesterday = today - timedelta(days=1)
|
||||
for day in [yesterday, today]:
|
||||
data = fetch_billing_data_for_day(process_day=day, service_id=service_id)
|
||||
@@ -35,11 +35,9 @@ def fetch_monthly_billing_for_year(service_id, year):
|
||||
yearly_data = db.session.query(
|
||||
func.date_trunc('month', FactBilling.bst_date).label("month"),
|
||||
func.sum(FactBilling.notifications_sent).label("notifications_sent"),
|
||||
func.sum(FactBilling.billable_units).label("billable_units"),
|
||||
func.sum(FactBilling.billable_units * FactBilling.rate_multiplier).label("billable_units"),
|
||||
FactBilling.service_id,
|
||||
FactBilling.rate,
|
||||
FactBilling.rate_multiplier,
|
||||
FactBilling.international,
|
||||
FactBilling.notification_type
|
||||
).filter(
|
||||
FactBilling.service_id == service_id,
|
||||
@@ -49,8 +47,6 @@ def fetch_monthly_billing_for_year(service_id, year):
|
||||
'month',
|
||||
FactBilling.service_id,
|
||||
FactBilling.rate,
|
||||
FactBilling.rate_multiplier,
|
||||
FactBilling.international,
|
||||
FactBilling.notification_type
|
||||
).order_by(
|
||||
FactBilling.service_id,
|
||||
@@ -125,7 +121,7 @@ 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,
|
||||
|
||||
@@ -100,7 +100,8 @@ def get_yearly_billing_data_for_date_range(
|
||||
MonthlyBilling.end_date <= end_date,
|
||||
MonthlyBilling.notification_type.in_(notification_types)
|
||||
).order_by(
|
||||
MonthlyBilling.notification_type
|
||||
MonthlyBilling.start_date,
|
||||
MonthlyBilling.notification_type,
|
||||
).all()
|
||||
|
||||
return results
|
||||
|
||||
Reference in New Issue
Block a user