From 4a7bfcc9c5dfb4ff96bfa01c09a0d7c3cbf25fc4 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Mon, 25 Jan 2021 12:54:23 +0000 Subject: [PATCH] Add billing details property This property lets service settings know if there are any billing details to preview. --- app/models/service.py | 27 ++++++++++++++++++----- app/templates/views/service-settings.html | 2 +- tests/__init__.py | 10 ++++++++- tests/app/models/test_service.py | 12 +++++++++- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/app/models/service.py b/app/models/service.py index e3a23fc54..af337b771 100644 --- a/app/models/service.py +++ b/app/models/service.py @@ -30,8 +30,16 @@ class Service(JSONModel): ALLOWED_PROPERTIES = { 'active', + 'allowed_broadcast_provider', + 'billing_contact_email_address', + 'billing_contact_name', + 'billing_reference', + 'consent_to_research', 'contact_link', + 'count_as_live', 'email_from', + 'go_live_at', + 'go_live_user', 'id', 'inbound_api', 'message_limit', @@ -39,16 +47,12 @@ class Service(JSONModel): 'name', 'notes', 'prefix_sms', + 'purchase_order_number', 'research_mode', 'service_callback_api', 'volume_email', 'volume_sms', 'volume_letter', - 'consent_to_research', - 'count_as_live', - 'go_live_user', - 'go_live_at', - 'allowed_broadcast_provider', } TEMPLATE_TYPES = ( @@ -76,6 +80,19 @@ class Service(JSONModel): def permissions(self): return self._dict.get('permissions', self.TEMPLATE_TYPES) + @property + def billing_details(self): + billing_details = [ + self.billing_contact_email_address, + self.billing_contact_name, + self.billing_reference, + self.purchase_order_number + ] + if any(billing_details): + return billing_details + else: + return None + def update(self, **kwargs): return service_api_client.update_service(self.id, **kwargs) diff --git a/app/templates/views/service-settings.html b/app/templates/views/service-settings.html index a4b939939..d03d7c6bc 100644 --- a/app/templates/views/service-settings.html +++ b/app/templates/views/service-settings.html @@ -337,7 +337,7 @@ {% call row() %} {{ text_field('Billing details')}} - {{ optional_text_field(None, default="No billing details yet", wrap=True) }} + {{ optional_text_field(current_service.billing_details, default="No billing details yet", wrap=True) }} {{ edit_field('Change', url_for('.service_settings', service_id=current_service.id), suffix='billing details for service') }} {% endcall %} diff --git a/tests/__init__.py b/tests/__init__.py index f30c4c251..1e853a3ba 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -151,6 +151,10 @@ def service_json( organisation_id=None, rate_limit=3000, notes=None, + billing_contact_email_address=None, + billing_contact_name=None, + billing_reference=None, + purchase_order_number=None ): if users is None: users = [] @@ -189,7 +193,11 @@ def service_json( 'consent_to_research': True, 'count_as_live': True, 'organisation': organisation_id, - 'notes': notes + 'notes': notes, + 'billing_contact_email_address': billing_contact_email_address, + 'billing_contact_name': billing_contact_name, + 'billing_reference': billing_reference, + 'purchase_order_number': purchase_order_number, } diff --git a/tests/app/models/test_service.py b/tests/app/models/test_service.py index 9c1eaa98d..1b29c2103 100644 --- a/tests/app/models/test_service.py +++ b/tests/app/models/test_service.py @@ -5,7 +5,7 @@ import pytest from app.models.organisation import Organisation from app.models.service import Service from app.models.user import User -from tests import organisation_json +from tests import organisation_json, service_json from tests.conftest import ORGANISATION_ID INV_PARENT_FOLDER_ID = '7e979e79-d970-43a5-ac69-b625a8d147b0' @@ -255,3 +255,13 @@ def test_bad_permission_raises(service_one): with pytest.raises(KeyError) as e: Service(service_one).has_permission('foo') assert str(e.value) == "'foo is not a service permission'" + + +@pytest.mark.parametrize("purchase_order_number,expected_result", [ + [None, None], + ["PO1234", [None, None, None, "PO1234"]] +]) +def test_service_billing_details(purchase_order_number, expected_result): + service = Service(service_json(purchase_order_number=purchase_order_number)) + service._dict['purchase_order_number'] = purchase_order_number + assert service.billing_details == expected_result