Use annual_billing tables at backend for getting and updating free_sms_fragment_limit

This commit is contained in:
venusbb
2017-10-31 11:22:57 +00:00
parent e665f35acc
commit 8ea38ba7b6
10 changed files with 161 additions and 17 deletions

View File

@@ -39,7 +39,7 @@ from app.main.forms import (
FreeSMSAllowance,
ServiceEditInboundNumberForm,
)
from app import user_api_client, current_service, organisations_client, inbound_number_client
from app import user_api_client, current_service, organisations_client, inbound_number_client, billing_api_client
from notifications_utils.formatters import formatted_list
@@ -89,6 +89,9 @@ def service_settings(service_id):
default_sms_sender = next(
(Field(x['sms_sender'], html='escape') for x in sms_senders if x['is_default']), "None"
)
free_sms_fragment_limit = billing_api_client.get_free_sms_fragment_limit_for_year(service_id)
return render_template(
'views/service-settings.html',
organisation=organisation,
@@ -103,7 +106,8 @@ def service_settings(service_id):
default_letter_contact_block=default_letter_contact_block,
letter_contact_details_count=letter_contact_details_count,
default_sms_sender=default_sms_sender,
sms_sender_count=sms_sender_count
sms_sender_count=sms_sender_count,
free_sms_fragment_limit=free_sms_fragment_limit
)
@@ -704,13 +708,16 @@ def set_organisation_type(service_id):
@user_has_permissions(admin_override=True)
def set_free_sms_allowance(service_id):
form = FreeSMSAllowance(free_sms_allowance=current_service['free_sms_fragment_limit'])
form = FreeSMSAllowance(free_sms_allowance=billing_api_client.get_free_sms_fragment_limit_for_year(service_id))
if form.validate_on_submit():
service_api_client.update_service(
service_id,
# TODO: Retire this after new end points are added.
free_sms_fragment_limit=form.free_sms_allowance.data,
)
form.set_free_sms_allowance = \
billing_api_client.create_or_update_free_sms_fragment_limit_for_year(service_id,
form.free_sms_allowance.data)
return redirect(url_for('.service_settings', service_id=service_id))
return render_template(