Use better date function to get the first of each month.

Build the json object to return for the new endpoint.
This commit is contained in:
Rebecca Law
2018-04-30 16:34:40 +01:00
parent 0fb9c1d318
commit 18c2b9a56d
4 changed files with 74 additions and 28 deletions

View File

@@ -32,14 +32,16 @@ register_errors(billing_blueprint)
@billing_blueprint.route('/ft-monthly-usage')
def get_yearly_usage_by_monthy_from_ft_billing(service_id):
def get_yearly_usage_by_monthly_from_ft_billing(service_id):
try:
year = int(request.args.get('year'))
results = fetch_monthly_billing_for_year(service_id=service_id, year=year)
serialize_ft_billing(results)
except TypeError:
return jsonify(result='error', message='No valid year provided'), 400
results = fetch_monthly_billing_for_year(service_id=service_id, year=year)
data = serialize_ft_billing(results)
return jsonify(monthly_usage=data)
@billing_blueprint.route('/monthly-usage')
def get_yearly_usage_by_month(service_id):
@@ -207,16 +209,15 @@ def update_free_sms_fragment_limit_data(service_id, free_sms_fragment_limit, fin
def serialize_ft_billing(data):
results = []
for d in data:
j = {
"Month": d.month,
"service_id": d.service_id,
"month": (datetime.strftime(d.month, "%B")),
"service_id": str(d.service_id),
"notifications_type": d.notification_type,
"notifications_sent": d.notifications_sent,
"billable_units": d.billable_units,
"rate": d.rate,
"rate_multiplier": d.rate_multiplier,
"notifications_sent": int(d.notifications_sent),
"billable_units": int(d.billable_units),
"rate": float(d.rate),
"rate_multiplier": int(d.rate_multiplier),
"international": d.international,
}
results.append(j)