From 8f21caa87acb72631a7f96005547b5ba71da3389 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Mon, 25 Jan 2021 15:40:49 +0000 Subject: [PATCH] Change service billing details View page that lets you change service billing details and update details on form submission. --- app/main/forms.py | 7 +++ app/main/views/service_settings.py | 22 +++++++- app/notify_client/service_api_client.py | 6 ++- .../edit-service-billing-details.html | 26 ++++++++++ tests/app/main/views/test_service_settings.py | 51 +++++++++++++++++++ 5 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 app/templates/views/service-settings/edit-service-billing-details.html diff --git a/app/main/forms.py b/app/main/forms.py index ea83a6720..2081dc755 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -1686,6 +1686,13 @@ class EditServiceNotesForm(StripWhitespaceForm): notes = TextAreaField(validators=[]) +class ServiceBillingDetailsForm(StripWhitespaceForm): + billing_contact_email_address = GovukTextInputField('Billing contact email address') + billing_contact_name = GovukTextInputField('Billing contact name') + billing_reference = GovukTextInputField('Billing reference') + purchase_order_number = GovukTextInputField('Purchase order number') + + class ServiceLetterContactBlockForm(StripWhitespaceForm): letter_contact_block = TextAreaField( validators=[ diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index f0cc167c3..b260a05ea 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -43,6 +43,7 @@ from app.main.forms import ( RateLimit, RenameServiceForm, SearchByNameForm, + ServiceBillingDetailsForm, ServiceContactDetailsForm, ServiceDataRetentionEditForm, ServiceDataRetentionForm, @@ -1213,7 +1214,26 @@ def edit_service_notes(service_id): @main.route("/services//edit-billing-details", methods=['GET', 'POST']) @user_is_platform_admin def edit_service_billing_details(service_id): - pass + form = ServiceBillingDetailsForm( + billing_contact_email_address=current_service.billing_contact_email_address, + billing_contact_name=current_service.billing_contact_name, + billing_reference=current_service.billing_reference, + purchase_order_number=current_service.purchase_order_number + ) + + if form.validate_on_submit(): + current_service.update( + billing_contact_email_address=form.billing_contact_email_address.data, + billing_contact_name=form.billing_contact_name.data, + billing_reference=form.billing_reference.data, + purchase_order_number=form.purchase_order_number.data + ) + return redirect(url_for('.service_settings', service_id=service_id)) + + return render_template( + 'views/service-settings/edit-service-billing-details.html', + form=form, + ) def get_branding_as_value_and_label(email_branding): diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index 4c93b2786..e29453d9a 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -80,10 +80,13 @@ class ServiceAPIClient(NotifyAdminAPIClient): data = _attach_current_user(kwargs) disallowed_attributes = set(data.keys()) - { 'active', + 'billing_contact_email_address', + 'billing_contact_name', + 'billing_reference', 'consent_to_research', 'contact_link', - 'count_as_live', 'created_by', + 'count_as_live', 'email_branding', 'email_from', 'free_sms_fragment_limit', @@ -97,6 +100,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): 'organisation_type', 'permissions', 'prefix_sms', + 'purchase_order_number', 'rate_limit', 'reply_to_email_address', 'research_mode', diff --git a/app/templates/views/service-settings/edit-service-billing-details.html b/app/templates/views/service-settings/edit-service-billing-details.html new file mode 100644 index 000000000..49d0748ef --- /dev/null +++ b/app/templates/views/service-settings/edit-service-billing-details.html @@ -0,0 +1,26 @@ + +{% extends "withnav_template.html" %} +{% from "components/page-header.html" import page_header %} +{% from "components/page-footer.html" import page_footer %} +{% from "components/form.html" import form_wrapper %} + +{% block service_page_title %} + Change service billing details +{% endblock %} + +{% block maincolumn_content %} + + {{ page_header( + 'Change service billing details', + back_link=url_for('main.service_settings', service_id=current_service.id) + ) }} + + {% call form_wrapper() %} + {{ form.billing_contact_name }} + {{ form.billing_contact_email_address }} + {{ form.billing_reference }} + {{ form.purchase_order_number }} + {{ page_footer('Save') }} + {% endcall %} + +{% endblock %} diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index a4eeeb6ea..89828849c 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -5300,3 +5300,54 @@ def test_service_settings_links_to_edit_service_billing_details_page_for_platfor )) page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') assert len(page.find_all('a', attrs={'href': '/services/{}/edit-billing-details'.format(SERVICE_ONE_ID)})) == 1 + + +def test_view_edit_service_billing_details( + platform_admin_client, + service_one, + +): + response = platform_admin_client.get(url_for('main.edit_service_billing_details', service_id=SERVICE_ONE_ID)) + page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') + assert page.select_one('h1').text == "Change service billing details" + labels = page.find_all('label', class_="form-label") + labels_list = [ + 'Billing contact email address', 'Billing contact name', 'Billing reference', 'Purchase order number' + ] + for label in labels: + assert label.text.strip() in labels_list + textbox_names = page.find_all('input', class_='govuk-input govuk-!-width-two-thirds') + names_list = ['billing_contact_email_address', 'billing_contact_name', 'billing_reference', 'purchase_order_number'] + + for name in textbox_names: + assert name.attrs["name"] in names_list + + +def test_update_service_billing_details( + platform_admin_client, + service_one, + mock_update_service +): + response = platform_admin_client.post( + url_for( + 'main.edit_service_billing_details', + service_id=SERVICE_ONE_ID, + ), + data={ + 'billing_contact_email_address': 'accounts@fluff.gov.uk', + 'billing_contact_name': 'Flannellette von Fluff', + 'billing_reference': '', + 'purchase_order_number': 'PO1234' + } + ) + assert response.status_code == 302 + settings_url = url_for( + 'main.service_settings', service_id=SERVICE_ONE_ID, _external=True) + assert response.location == settings_url + mock_update_service.assert_called_with( + SERVICE_ONE_ID, + billing_contact_email_address='accounts@fluff.gov.uk', + billing_contact_name='Flannellette von Fluff', + billing_reference='', + purchase_order_number='PO1234' + )