Skip to content

Commit

Permalink
Check HLPAS eligibility from subcategory
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMillar-MOJ committed Mar 10, 2025
1 parent 9f5a539 commit 4aaf3e3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/categories/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,7 @@ def init_children(category: Category) -> None:

def get_category_from_code(code: str) -> Category:
return ALL_CATEGORIES[code]


def get_subcategory_from_code(parent_code: str, code: str) -> Category:
return get_category_from_code(parent_code).children[code]
9 changes: 5 additions & 4 deletions app/means_test/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flask_babel import lazy_gettext as _, gettext
from werkzeug.datastructures import MultiDict
from app.means_test.api import update_means_test, get_means_test_payload, is_eligible
from app.means_test.constants import EligibilityResult
from app.means_test.constants import EligibilityState
from app.means_test.forms.about_you import AboutYouForm
from app.means_test.forms.benefits import BenefitsForm, AdditionalBenefitsForm
from app.means_test.forms.property import MultiplePropertiesForm
Expand Down Expand Up @@ -66,9 +66,9 @@ def dispatch_request(self):
reference = update_means_test(payload)["reference"]

eligibility = is_eligible(reference)
if eligibility == EligibilityResult.ELIGIBLE:
if eligibility == EligibilityState.ELIGIBLE:
return redirect(url_for("contact.eligible"))
if eligibility == EligibilityResult.INELIGIBLE:
if eligibility == EligibilityState.INELIGIBLE:
return redirect(url_for("means_test.result.ineligible"))

return redirect(next_page)
Expand Down Expand Up @@ -268,7 +268,8 @@ def __init__(self, template: str = None):

def dispatch_request(self):
category = session.category
if category.eligible_for_HLPAS:
subcategory = session.subcategory
if subcategory.eligible_for_HLPAS:
return redirect(url_for("means_test.result.hlpas"))
return render_template(self.template, category=category)

Expand Down
23 changes: 21 additions & 2 deletions app/session.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from flask.sessions import SecureCookieSession, SecureCookieSessionInterface
from app.categories.constants import Category, get_category_from_code
from app.categories.constants import (
Category,
get_category_from_code,
get_subcategory_from_code,
)
from flask import session
from dataclasses import dataclass
from datetime import timedelta
from app.categories.models import CategoryAnswer
from app.categories.models import CategoryAnswer, QuestionType
from flask_babel import LazyString


Expand Down Expand Up @@ -153,6 +157,21 @@ def category(self, category: Category):
self["category_answers"] = []
self["category"] = self._category_to_dict_for_session_storage(category)

@property
def subcategory(self) -> Category | None:
"""
Returns the subcategory based on category answers.
Returns:
Category: The subcategory object if found, None otherwise.
"""
for answer in self.category_answers:
if answer.question_type == QuestionType.SUB_CATEGORY:
return get_subcategory_from_code(
answer.category.parent_code, answer.category.code
)
return None

@staticmethod
def _category_to_dict_for_session_storage(category: Category):
data = {"code": category.code}
Expand Down

0 comments on commit 4aaf3e3

Please sign in to comment.