mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-11 09:27:56 -04:00
Update the organsition usage endpoint to use the new query.
This endpoint may need to change, but we'd like to see how this performs, so we'll test this with a real data set. Then come back to make sure the format is correct and check for missing tests for the endpoint,
This commit is contained in:
@@ -594,7 +594,6 @@ def fetch_email_usage_for_organisation(organisation_id, start_date, end_date):
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def fetch_sms_billing_for_organisation(organisation_id, start_date, end_date):
|
||||
|
||||
# ASSUMPTION: AnnualBilling has been populated for year.
|
||||
free_allowance_remainder = fetch_sms_free_allowance_remainder(start_date).subquery()
|
||||
|
||||
@@ -675,15 +674,15 @@ def fetch_usage_year_for_organisation(organisation_id, year):
|
||||
|
||||
for usage in sms_usages:
|
||||
service_with_usage[str(usage.service_id)] = {
|
||||
'service_id': usage.service_id,
|
||||
'service_name': usage.service_name,
|
||||
'free_sms_limit': usage.free_sms_fragment_limit,
|
||||
'sms_remainder': usage.sms_remainder,
|
||||
'sms_billable_units': usage.sms_billable_units,
|
||||
'chargeable_billable_sms': usage.chargeable_billable_sms,
|
||||
'sms_cost': usage.sms_cost,
|
||||
'letter_cost': 0,
|
||||
'emails_sent': 0
|
||||
'service_id': usage.service_id,
|
||||
'service_name': usage.service_name,
|
||||
'free_sms_limit': usage.free_sms_fragment_limit,
|
||||
'sms_remainder': usage.sms_remainder,
|
||||
'sms_billable_units': usage.sms_billable_units,
|
||||
'chargeable_billable_sms': usage.chargeable_billable_sms,
|
||||
'sms_cost': usage.sms_cost,
|
||||
'letter_cost': 0,
|
||||
'emails_sent': 0
|
||||
}
|
||||
for letter_usage in letter_usages:
|
||||
service_with_usage[str(letter_usage.service_id)]['letter_cost'] = letter_usage.letter_cost
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
from datetime import datetime
|
||||
|
||||
from flask import abort, Blueprint, jsonify, request, current_app
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from app.config import QueueNames
|
||||
from app.dao.fact_billing_dao import fetch_usage_year_for_organisation
|
||||
from app.dao.organisation_dao import (
|
||||
dao_create_organisation,
|
||||
dao_get_organisations,
|
||||
@@ -127,9 +130,9 @@ def get_organisation_services(organisation_id):
|
||||
|
||||
@organisation_blueprint.route('/<uuid:organisation_id>/services-with-usage', methods=['GET'])
|
||||
def get_organisation_services_usage(organisation_id):
|
||||
services = dao_get_organisation_services(organisation_id)
|
||||
sorted_services = sorted(services, key=lambda s: (-s.active, s.name))
|
||||
return jsonify([s.serialize_for_org_dashboard() for s in sorted_services])
|
||||
services = fetch_usage_year_for_organisation(organisation_id, datetime.utcnow().year)
|
||||
|
||||
return jsonify(services=services)
|
||||
|
||||
|
||||
@organisation_blueprint.route('/<uuid:organisation_id>/users/<uuid:user_id>', methods=['POST'])
|
||||
|
||||
Reference in New Issue
Block a user