mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
Add queries to handle returning usage for all services associated to a given organisation.
This commit is contained in:
@@ -12,6 +12,7 @@ from app.dao.date_util import (
|
|||||||
get_financial_year,
|
get_financial_year,
|
||||||
get_financial_year_for_datetime
|
get_financial_year_for_datetime
|
||||||
)
|
)
|
||||||
|
from app.dao.organisation_dao import dao_get_organisation_services
|
||||||
|
|
||||||
from app.models import (
|
from app.models import (
|
||||||
FactBilling,
|
FactBilling,
|
||||||
|
|||||||
@@ -125,6 +125,13 @@ def get_organisation_services(organisation_id):
|
|||||||
return jsonify([s.serialize_for_org_dashboard() for s in sorted_services])
|
return jsonify([s.serialize_for_org_dashboard() for s in sorted_services])
|
||||||
|
|
||||||
|
|
||||||
|
@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])
|
||||||
|
|
||||||
|
|
||||||
@organisation_blueprint.route('/<uuid:organisation_id>/users/<uuid:user_id>', methods=['POST'])
|
@organisation_blueprint.route('/<uuid:organisation_id>/users/<uuid:user_id>', methods=['POST'])
|
||||||
def add_user_to_organisation(organisation_id, user_id):
|
def add_user_to_organisation(organisation_id, user_id):
|
||||||
new_org_user = dao_add_user_to_organisation(organisation_id, user_id)
|
new_org_user = dao_add_user_to_organisation(organisation_id, user_id)
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ from app.dao.fact_billing_dao import (
|
|||||||
get_rates_for_billing,
|
get_rates_for_billing,
|
||||||
fetch_sms_free_allowance_remainder,
|
fetch_sms_free_allowance_remainder,
|
||||||
fetch_sms_billing_for_all_services,
|
fetch_sms_billing_for_all_services,
|
||||||
fetch_letter_costs_for_all_services, fetch_letter_line_items_for_all_services)
|
fetch_letter_costs_for_all_services, fetch_letter_line_items_for_all_services, fetch_usage_year_for_organisation
|
||||||
|
)
|
||||||
from app.dao.organisation_dao import dao_add_service_to_organisation
|
from app.dao.organisation_dao import dao_add_service_to_organisation
|
||||||
from app.models import (
|
from app.models import (
|
||||||
FactBilling,
|
FactBilling,
|
||||||
@@ -592,7 +593,8 @@ def test_fetch_sms_billing_for_all_services_with_remainder(notify_db_session):
|
|||||||
|
|
||||||
|
|
||||||
def test_fetch_sms_billing_for_all_services_without_an_organisation_appears(notify_db_session):
|
def test_fetch_sms_billing_for_all_services_without_an_organisation_appears(notify_db_session):
|
||||||
org, org_2, service, service_2, service_3, service_sms_only = set_up_usage_data(datetime(2019, 5, 1))
|
org, org_2, service, service_2, service_3, service_sms_only, \
|
||||||
|
org_with_emails, service_with_emails = set_up_usage_data(datetime(2019, 5, 1))
|
||||||
results = fetch_sms_billing_for_all_services(datetime(2019, 5, 1), datetime(2019, 5, 31))
|
results = fetch_sms_billing_for_all_services(datetime(2019, 5, 1), datetime(2019, 5, 31))
|
||||||
|
|
||||||
assert len(results) == 2
|
assert len(results) == 2
|
||||||
@@ -604,7 +606,8 @@ def test_fetch_sms_billing_for_all_services_without_an_organisation_appears(noti
|
|||||||
|
|
||||||
|
|
||||||
def test_fetch_letter_costs_for_all_services(notify_db_session):
|
def test_fetch_letter_costs_for_all_services(notify_db_session):
|
||||||
org, org_2, service, service_2, service_3, service_sms_only = set_up_usage_data(datetime(2019, 6, 1))
|
org, org_2, service, service_2, service_3, service_sms_only, \
|
||||||
|
org_with_emails, service_with_emails = set_up_usage_data(datetime(2019, 6, 1))
|
||||||
|
|
||||||
results = fetch_letter_costs_for_all_services(datetime(2019, 6, 1), datetime(2019, 9, 30))
|
results = fetch_letter_costs_for_all_services(datetime(2019, 6, 1), datetime(2019, 9, 30))
|
||||||
|
|
||||||
@@ -615,7 +618,8 @@ def test_fetch_letter_costs_for_all_services(notify_db_session):
|
|||||||
|
|
||||||
|
|
||||||
def test_fetch_letter_line_items_for_all_service(notify_db_session):
|
def test_fetch_letter_line_items_for_all_service(notify_db_session):
|
||||||
org_1, org_2, service_1, service_2, service_3, service_sms_only = set_up_usage_data(datetime(2019, 6, 1))
|
org_1, org_2, service_1, service_2, service_3, service_sms_only, \
|
||||||
|
org_with_emails, service_with_emails = set_up_usage_data(datetime(2019, 6, 1))
|
||||||
|
|
||||||
results = fetch_letter_line_items_for_all_services(datetime(2019, 6, 1), datetime(2019, 9, 30))
|
results = fetch_letter_line_items_for_all_services(datetime(2019, 6, 1), datetime(2019, 9, 30))
|
||||||
|
|
||||||
@@ -625,3 +629,12 @@ def test_fetch_letter_line_items_for_all_service(notify_db_session):
|
|||||||
assert results[2] == (org_2.name, org_2.id, service_2.name, service_2.id, Decimal("0.65"), 'second', 20)
|
assert results[2] == (org_2.name, org_2.id, service_2.name, service_2.id, Decimal("0.65"), 'second', 20)
|
||||||
assert results[3] == (org_2.name, org_2.id, service_2.name, service_2.id, Decimal("0.50"), 'first', 2)
|
assert results[3] == (org_2.name, org_2.id, service_2.name, service_2.id, Decimal("0.50"), 'first', 2)
|
||||||
assert results[4] == (None, None, service_3.name, service_3.id, Decimal("0.55"), 'second', 15)
|
assert results[4] == (None, None, service_3.name, service_3.id, Decimal("0.55"), 'second', 15)
|
||||||
|
|
||||||
|
|
||||||
|
def test_fetch_usage_year_for_organisation(notify_db_session):
|
||||||
|
org, org_2, service, service_2, service_3, service_sms_only, \
|
||||||
|
org_with_emails, service_with_emails = set_up_usage_data(datetime(2019, 5, 1))
|
||||||
|
|
||||||
|
results = fetch_usage_year_for_organisation(org.id, 2019)
|
||||||
|
results = fetch_usage_year_for_organisation(org_2.id, 2019)
|
||||||
|
results = fetch_usage_year_for_organisation(org_with_emails.id, 2019)
|
||||||
|
|||||||
@@ -906,6 +906,11 @@ def set_up_usage_data(start_date):
|
|||||||
org = create_organisation(name="Org for {}".format(service.name))
|
org = create_organisation(name="Org for {}".format(service.name))
|
||||||
dao_add_service_to_organisation(service=service, organisation_id=org.id)
|
dao_add_service_to_organisation(service=service, organisation_id=org.id)
|
||||||
|
|
||||||
|
service_2 = create_service(service_name='b - emails')
|
||||||
|
email_template = create_template(service=service_2, template_type='email')
|
||||||
|
org_2 = create_organisation(name='Org for {}'.format(service_2))
|
||||||
|
dao_add_service_to_organisation(service=service_2, organisation_id=org_2.id)
|
||||||
|
|
||||||
service_3 = create_service(service_name='c - letters only')
|
service_3 = create_service(service_name='c - letters only')
|
||||||
letter_template_3 = create_template(service=service_3, template_type='letter')
|
letter_template_3 = create_template(service=service_3, template_type='letter')
|
||||||
org_3 = create_organisation(name="Org for {}".format(service_3.name))
|
org_3 = create_organisation(name="Org for {}".format(service_3.name))
|
||||||
@@ -942,7 +947,9 @@ def set_up_usage_data(start_date):
|
|||||||
create_ft_billing(bst_date=two_days_later, template=letter_template_4,
|
create_ft_billing(bst_date=two_days_later, template=letter_template_4,
|
||||||
notifications_sent=15, billable_unit=4, rate=.55, postage='second')
|
notifications_sent=15, billable_unit=4, rate=.55, postage='second')
|
||||||
|
|
||||||
return org, org_3, service, service_3, service_4, service_sms_only
|
create_ft_billing(bst_date=start_date, template=email_template, notifications_sent=10)
|
||||||
|
|
||||||
|
return org, org_3, service, service_3, service_4, service_sms_only, org_2, service_2
|
||||||
|
|
||||||
|
|
||||||
def create_returned_letter(service=None, reported_at=None, notification_id=None):
|
def create_returned_letter(service=None, reported_at=None, notification_id=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user