Skip to content

Commit

Permalink
Merge pull request #411 from UKGovernmentBEIS/PC-1464-Improve-select-…
Browse files Browse the repository at this point in the history
…your-supplier-question

PC-1464: Improve select your supplier question
  • Loading branch information
samyou-softwire authored Dec 17, 2024
2 parents fbb2380 + dc6469a commit 111673c
Show file tree
Hide file tree
Showing 14 changed files with 503 additions and 222 deletions.
14 changes: 11 additions & 3 deletions help_to_heat/frontdoor/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
country_page = "country"
northern_ireland_ineligible_page = "northern-ireland"
supplier_page = "supplier"
alternative_supplier_page = "alternative-supplier"
own_property_page = "own-property"
bulb_warning_page = "bulb-warning-page"
shell_warning_page = "shell-warning-page"
Expand Down Expand Up @@ -43,6 +44,7 @@
country_page,
northern_ireland_ineligible_page,
supplier_page,
alternative_supplier_page,
own_property_page,
bulb_warning_page,
shell_warning_page,
Expand Down Expand Up @@ -91,6 +93,8 @@
country_field_wales = "Wales"
country_field_northern_ireland = "Northern Ireland"

# if needing to query this, in most cases use SupplierConverter.get_supplier()
# it handles the user selecting an alternative
supplier_field = "supplier"
supplier_field_british_gas = "British Gas"
supplier_field_bulb = "Bulb, now part of Octopus Energy"
Expand All @@ -104,7 +108,7 @@
supplier_field_shell = "Shell"
supplier_field_utilita = "Utilita"
supplier_field_utility_warehouse = "Utility Warehouse"
supplier_fields = [
supplier_field_values_real = [
supplier_field_british_gas,
supplier_field_bulb,
supplier_field_e,
Expand All @@ -118,6 +122,10 @@
supplier_field_utilita,
supplier_field_utility_warehouse,
]
supplier_field_not_listed = "supplier_not_listed"

alternative_supplier_field = "alternative_supplier"

user_selected_supplier_field = "user_selected_supplier"

bulb_warning_page_field = "confirm_bulb_warning"
Expand All @@ -131,7 +139,7 @@
own_property_field_tenant = "No, I am a tenant"
own_property_field_social_housing = "No, I am a social housing tenant"
own_property_field_landlord = "Yes, I am the property owner but I lease the property to one or more tenants"
own_property_fields_non_social_housing = [
own_property_field_values_non_social_housing = [
own_property_field_own_property,
own_property_field_tenant,
own_property_field_landlord,
Expand Down Expand Up @@ -196,7 +204,7 @@
council_tax_band_field_g = "G"
council_tax_band_field_h = "H"
council_tax_band_field_i = "I"
council_tax_band_fields = [
council_tax_band_field_values = [
council_tax_band_field_a,
council_tax_band_field_b,
council_tax_band_field_c,
Expand Down
54 changes: 45 additions & 9 deletions help_to_heat/frontdoor/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from . import models, schemas
from .consts import (
all_pages,
alternative_supplier_field,
alternative_supplier_page,
confirm_and_submit_page,
epc_accept_suggested_epc_field,
epc_accept_suggested_epc_field_not_found,
Expand All @@ -34,6 +36,13 @@
property_type_field,
property_type_field_park_home,
supplier_field,
supplier_field_bulb,
supplier_field_eon_next,
supplier_field_not_listed,
supplier_field_octopus,
supplier_field_shell,
supplier_field_utility_warehouse,
supplier_page,
)
from .epc_api import EPCApi
from .os_api import OSApi, ThrottledApiException
Expand Down Expand Up @@ -161,38 +170,65 @@ def get_addresses_from_api(postcode):
class SupplierConverter:
def __init__(self, session_id):
self.session_id = session_id
self.supplier = None
self.alternative_supplier = None

def _get_supplier(self):
return api.session.get_answer(self.session_id, "supplier")["supplier"]
def get_supplier(self):
supplier = self._get_supplier_from_session()
alternative_supplier = self._get_alternative_supplier_from_session()

return alternative_supplier if self._did_specify_alternative() else supplier

def _get_supplier_from_session(self):
if self.supplier is None:
self.supplier = api.session.get_answer(self.session_id, supplier_page).get(supplier_field)

return self.supplier

def _get_alternative_supplier_from_session(self):
if self.alternative_supplier is None:
self.alternative_supplier = api.session.get_answer(self.session_id, alternative_supplier_page).get(
alternative_supplier_field
)

return self.alternative_supplier

def _did_specify_alternative(self):
supplier = self._get_supplier_from_session()
return supplier == supplier_field_not_listed

def _is_bulb(self):
return self._get_supplier() == "Bulb, now part of Octopus Energy"
return self.get_supplier() == supplier_field_bulb

def _is_utility_warehouse(self):
return self._get_supplier() == "Utility Warehouse"
return self.get_supplier() == supplier_field_utility_warehouse

def _is_shell(self):
return self._get_supplier() == "Shell"
return self.get_supplier() == supplier_field_shell

def get_supplier_on_general_pages(self):
supplier = self._get_supplier()
supplier = self.get_supplier()
if self._is_bulb():
return supplier + ", "
return supplier

def get_supplier_on_success_page(self):
supplier = self._get_supplier()
supplier = self.get_supplier()
if self._is_bulb() or self._is_shell():
return "Octopus Energy"
if self._is_utility_warehouse():
return "E.ON Next"
return supplier

def replace_in_session_data(self, session_data):
if self._did_specify_alternative():
alternative_supplier = self._get_alternative_supplier_from_session()
session_data[supplier_field] = alternative_supplier

if self._is_bulb() or self._is_shell():
session_data["supplier"] = "Octopus Energy"
session_data[supplier_field] = supplier_field_octopus
if self._is_utility_warehouse():
session_data["supplier"] = "E.ON Next"
session_data[supplier_field] = supplier_field_eon_next
return session_data


Expand Down
34 changes: 26 additions & 8 deletions help_to_heat/frontdoor/routing/forwards_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
address_select_choice_journey_field_select_address,
address_select_manual_page,
address_select_page,
alternative_supplier_field,
alternative_supplier_page,
benefits_field,
benefits_page,
bulb_warning_page,
Expand Down Expand Up @@ -56,7 +58,7 @@
number_of_bedrooms_page,
own_property_field,
own_property_field_social_housing,
own_property_fields_non_social_housing,
own_property_field_values_non_social_housing,
own_property_page,
park_home_field,
park_home_ineligible_page,
Expand All @@ -81,6 +83,7 @@
supplier_field_edf,
supplier_field_eon_next,
supplier_field_foxglove,
supplier_field_not_listed,
supplier_field_octopus,
supplier_field_ovo,
supplier_field_scottish_power,
Expand Down Expand Up @@ -140,6 +143,9 @@ def get_next_page(current_page, answers):
if current_page == supplier_page:
return _supplier_next_page(answers)

if current_page == alternative_supplier_page:
return _alternative_supplier_next_page(answers)

if current_page == bulb_warning_page:
return _bulb_warning_page_next_page(answers)

Expand Down Expand Up @@ -247,9 +253,7 @@ def _country_next_page(answers):
return _unknown_response


@_requires_answer(supplier_field)
def _supplier_next_page(answers):
supplier = answers.get(supplier_field)
def _post_select_supplier_next_page(supplier):
if supplier in [
supplier_field_british_gas,
supplier_field_e,
Expand All @@ -271,6 +275,20 @@ def _supplier_next_page(answers):
return _unknown_response


@_requires_answer(supplier_field)
def _supplier_next_page(answers):
supplier = answers.get(supplier_field)
if supplier == supplier_field_not_listed:
return alternative_supplier_page
return _post_select_supplier_next_page(supplier)


@_requires_answer(alternative_supplier_field)
def _alternative_supplier_next_page(answers):
supplier = answers.get(alternative_supplier_field)
return _post_select_supplier_next_page(supplier)


# the answers object is not used by the function but is used by the decorator
@_requires_answer(bulb_warning_page_field)
def _bulb_warning_page_next_page(_answers):
Expand All @@ -290,7 +308,7 @@ def _utility_warehouse_warning_page_next_page(_answers):
@_requires_answer(own_property_field)
def _own_property_next_page(answers):
own_property = answers.get(own_property_field)
if own_property in own_property_fields_non_social_housing:
if own_property in own_property_field_values_non_social_housing:
return park_home_page
if own_property == own_property_field_social_housing:
return address_page
Expand Down Expand Up @@ -398,7 +416,7 @@ def _referral_already_submitted_next_page(answers):
def _post_duplicate_uprn_next_page(answers):
own_property = answers.get(own_property_field)
park_home = answers.get(park_home_field)
if own_property in own_property_fields_non_social_housing:
if own_property in own_property_field_values_non_social_housing:
if park_home == field_no:
return council_tax_band_page
if park_home == field_yes:
Expand Down Expand Up @@ -454,7 +472,7 @@ def _no_epc_next_page(answers):
# ask circumstances questions, depending on flow
def _post_epc_next_page(answers):
own_property = answers.get(own_property_field)
if own_property in own_property_fields_non_social_housing:
if own_property in own_property_field_values_non_social_housing:
return benefits_page
if own_property == own_property_field_social_housing:
return _post_circumstances_next_page(answers)
Expand Down Expand Up @@ -489,7 +507,7 @@ def _household_income_next_page(answers):
def _post_circumstances_next_page(answers):
own_property = answers.get(own_property_field)
park_home = answers.get(park_home_field)
if own_property in own_property_fields_non_social_housing:
if own_property in own_property_field_values_non_social_housing:
if park_home == field_no:
return property_type_page
if park_home == field_yes:
Expand Down
11 changes: 9 additions & 2 deletions help_to_heat/frontdoor/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
address_page,
address_select_manual_page,
address_select_page,
alternative_supplier_page,
benefits_field,
benefits_page,
bulb_warning_page,
Expand Down Expand Up @@ -114,6 +115,7 @@
supplier_field_edf,
supplier_field_eon_next,
supplier_field_foxglove,
supplier_field_not_listed,
supplier_field_octopus,
supplier_field_ovo,
supplier_field_scottish_power,
Expand Down Expand Up @@ -161,7 +163,7 @@
loft_insulation_field: _("Is there 100mm of insulation in your loft?"),
}

confirm_sumbit_map = {
confirm_submit_map = {
supplier_field: _("Energy supplier"),
contact_details_first_name_field: _("First name"),
contact_details_last_name_field: _("Last name"),
Expand Down Expand Up @@ -218,6 +220,7 @@
change_page_lookup = {
country_page: summary_page,
supplier_page: summary_page,
alternative_supplier_page: summary_page,
bulb_warning_page: summary_page,
shell_warning_page: summary_page,
utility_warehouse_warning_page: summary_page,
Expand Down Expand Up @@ -264,6 +267,7 @@
park_home_ineligible_page,
epc_ineligible_page,
property_ineligible_page,
alternative_supplier_page,
]

# where the journey starts for questions in this change page
Expand Down Expand Up @@ -853,7 +857,10 @@ class SessionSchema(Schema):
loft_insulation = fields.String(
validate=validate.OneOf(tuple(item["value"] for item in loft_insulation_validation_options_map))
)
supplier = fields.String(validate=validate.OneOf(tuple(item["value"] for item in supplier_options)))
supplier = fields.String(
validate=validate.OneOf(tuple(item["value"] for item in supplier_options) + (supplier_field_not_listed,))
)
alternative_supplier = fields.String(validate=validate.OneOf(tuple(item["value"] for item in supplier_options)))
user_selected_supplier = fields.String(validate=validate.OneOf(tuple(item["value"] for item in supplier_options)))
first_name = fields.String(validate=validate.Length(max=128))
last_name = fields.String(validate=validate.Length(max=128))
Expand Down
Loading

0 comments on commit 111673c

Please sign in to comment.