diff --git a/README.md b/README.md index 26c2431fb..26ab070d9 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ The JSON should follow the structure: } } }, - "depends_on": { "question_key": "answer_value_required_for_this_page_to_be_shown" } + "depends_on": [{ "question_key": "answer_value_required_for_this_page_to_be_shown" }] } } } @@ -171,9 +171,9 @@ Assumptions made by the format: ```jsonc "page_1": { "questions": { "question_1: "answer_options": ["A", "B"] } }, - "page_2": { "questions": { "question_2: "answer_options": ["C", "D"] }, "depends_on": { "question_1": "A" } }, - "page_3": { "questions": { "question_3: "answer_options": ["E", "F"] }, "depends_on": { "question_1": "A" } }, - "page_4": { "questions": { "question_4: "answer_options": ["G", "H"] }, "depends_on": { "question_1": "B" } }, + "page_2": { "questions": { "question_2: "answer_options": ["C", "D"] }, "depends_on": [{ "question_1": "A" }] }, + "page_3": { "questions": { "question_3: "answer_options": ["E", "F"] }, "depends_on": [{ "question_1": "A" }] }, + "page_4": { "questions": { "question_4: "answer_options": ["G", "H"] }, "depends_on": [{ "question_1": "B" }] }, ``` ## JSON Form Validation against Schema diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index a6935f620..148f2f1e7 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -35,11 +35,11 @@ module TasklistHelper end def subsection_link(subsection, case_log) - next_page_path = if subsection.status(case_log) != :cannot_start_yet - first_page_or_check_answers(subsection, case_log) - else - "#" - end - govuk_link_to(subsection.label, next_page_path.to_s.dasherize, class: "task-name") + if subsection.status(case_log) != :cannot_start_yet + next_page_path = first_page_or_check_answers(subsection, case_log).to_s + govuk_link_to(subsection.label, next_page_path.dasherize, aria: { describedby: subsection.id.dasherize }) + else + subsection.label + end end end diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 3657628ae..5e8380e7a 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -135,6 +135,9 @@ class CaseLog < ApplicationRecord enum postcode_known: POLAR, _suffix: true enum la_known: POLAR, _suffix: true enum net_income_known: NET_INCOME_KNOWN, _suffix: true + enum household_charge: POLAR, _suffix: true + enum is_carehome: POLAR, _suffix: true + enum nocharge: POLAR, _suffix: true AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing].freeze @@ -239,12 +242,16 @@ private case net_income_known when "Yes – the household has a weekly income" self.incfreq = "Weekly" + self.incref = nil when "Yes – the household has a monthly income" self.incfreq = "Monthly" + self.incref = nil when "Yes – the household has a yearly income" self.incfreq = "Yearly" + self.incref = nil when "Tenant prefers not to say" self.incref = 1 + self.incfreq = nil end self.hhmemb = other_hhmemb + 1 if other_hhmemb.present? self.renttype = RENT_TYPE_MAPPING[rent_type] @@ -253,6 +260,8 @@ private self.totelder = get_totelder self.totadult = get_totadult self.tcharge = brent.to_i + scharge.to_i + pscharge.to_i + supcharg.to_i + self.has_benefits = get_has_benefits + self.nocharge = household_charge == "Yes" ? "No" : "Yes" end def process_postcode_changes! @@ -303,6 +312,10 @@ private end end + def get_has_benefits + return "Yes" if HAS_BENEFITS_OPTIONS.include?(hb) + end + def all_fields_completed? mandatory_fields.none? { |field| public_send(field).nil? if respond_to?(field) } end diff --git a/app/models/constants/case_log.rb b/app/models/constants/case_log.rb index 36b2d8cdb..bf9fc55fa 100644 --- a/app/models/constants/case_log.rb +++ b/app/models/constants/case_log.rb @@ -206,15 +206,14 @@ module Constants::CaseLog PERIOD = { "Weekly for 52 weeks" => 1, - "Fortnightly" => 2, - "Four-weekly" => 3, - "Calendar monthly" => 4, + "Every 2 weeks" => 2, + "Every 4 weeks" => 3, + "Every calendar month" => 4, "Weekly for 50 weeks" => 5, "Weekly for 49 weeks" => 6, "Weekly for 48 weeks" => 7, "Weekly for 47 weeks" => 8, "Weekly for 46 weeks" => 9, - "Weekly for 53 weeks" => 10, }.freeze LATIME = { @@ -229,13 +228,13 @@ module Constants::CaseLog }.freeze HOUSING_BENEFIT = { - "Housing Benefit, but not Universal Credit" => 1, - "Universal Credit with housing element, but not Housing Benefit" => 6, - "Universal Credit without housing element and no Housing Benefit" => 7, - "Universal Credit and Housing Benefit" => 8, - "Not Housing Benefit or Universal Credit" => 9, - "Don’t know" => 3, - "Prefer not to say" => 100, + "Housing benefit" => 1, + "Universal Credit with housing element (excluding housing benefit)" => 6, + "Universal Credit (without housing element)" => 7, + "Housing benefit and Universal Credit (without housing element)" => 8, + "None" => 9, + "Don't know" => 3, + "Tenant prefers not to say" => 100, }.freeze REASON = { @@ -1077,4 +1076,9 @@ module Constants::CaseLog "Yes – the household has a yearly income" => 2, "Tenant prefers not to say" => 3, }.freeze + + HAS_BENEFITS_OPTIONS = ["Housing benefit", + "Universal Credit with housing element (excluding housing benefit)", + "Universal Credit (without housing element)", + "Housing benefit and Universal Credit (without housing element)"].freeze end diff --git a/app/models/form.rb b/app/models/form.rb index 4474eae8e..647ddf59e 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -59,11 +59,13 @@ class Form end def invalidated_questions(case_log) - (invalidated_page_questions(case_log) + invalidated_conditional_questions(case_log)).uniq + invalidated_page_questions(case_log) + invalidated_conditional_questions(case_log) end def invalidated_page_questions(case_log) - invalidated_pages(case_log).flat_map(&:questions) || [] + pages_that_are_routed_to = pages.select { |p| p.routed_to?(case_log) } + enabled_question_ids = pages_that_are_routed_to.flat_map(&:questions).map(&:id) || [] + invalidated_pages(case_log).flat_map(&:questions).reject { |q| enabled_question_ids.include?(q.id) } || [] end def invalidated_conditional_questions(case_log) diff --git a/app/models/form/page.rb b/app/models/form/page.rb index c550114a2..2fe6c00d0 100644 --- a/app/models/form/page.rb +++ b/app/models/form/page.rb @@ -32,8 +32,10 @@ private def depends_on_met(case_log) return true unless depends_on - depends_on.all? do |question, value| - !case_log[question].nil? && case_log[question] == value + depends_on.any? do |conditions_set| + conditions_set.all? do |question, value| + value.nil? ? case_log[question] == value : !case_log[question].nil? && case_log[question] == value + end end end end diff --git a/app/models/form/subsection.rb b/app/models/form/subsection.rb index d0445348c..36afa531f 100644 --- a/app/models/form/subsection.rb +++ b/app/models/form/subsection.rb @@ -18,8 +18,10 @@ class Form::Subsection def enabled?(case_log) return true unless depends_on - depends_on.all? do |subsection_id, dependent_status| - form.get_subsection(subsection_id).status(case_log) == dependent_status.to_sym + depends_on.any? do |conditions_set| + conditions_set.all? do |subsection_id, dependent_status| + form.get_subsection(subsection_id).status(case_log) == dependent_status.to_sym + end end end diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index d4cad6f8e..c9088d30c 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -38,15 +38,15 @@ module Validations::FinancialValidations def validate_hbrentshortfall(record) is_present = record.hbrentshortfall.present? is_yes = record.hbrentshortfall == "Yes" - hb_donotknow = record.hb == "Don’t know" - hb_no_hb_or_uc = record.hb == "Not Housing Benefit or Universal Credit" - hb_uc_no_hb = record.hb == "Universal Credit without housing element and no Housing Benefit" - hb_no_uc = record.hb == "Housing Benefit, but not Universal Credit" - hb_uc_no_he_hb = record.hb == "Universal Credit with housing element, but not Housing Benefit" - hb_and_uc = record.hb == "Universal Credit and Housing Benefit" + hb_donotknow = record.hb == "Don't know" + hb_none = record.hb == "None" + hb_uc_no_hb = record.hb == "Universal Credit (without housing element)" + hb_no_uc = record.hb == "Housing benefit" + hb_uc_no_he_hb = record.hb == "Universal Credit with housing element (excluding housing benefit)" + hb_and_uc = record.hb == "Housing benefit and Universal Credit (without housing element)" conditions = [ - { condition: is_yes && (hb_donotknow || hb_no_hb_or_uc || hb_uc_no_hb), error: I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits") }, + { condition: is_yes && (hb_donotknow || hb_none || hb_uc_no_hb), error: I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits") }, { condition: (hb_no_uc || hb_uc_no_he_hb || hb_and_uc) && !is_present, error: I18n.t("validations.financial.hbrentshortfall.amount_required") }, ] diff --git a/app/views/case_logs/_tasklist.html.erb b/app/views/case_logs/_tasklist.html.erb index 6765d6f82..85a8d6349 100644 --- a/app/views/case_logs/_tasklist.html.erb +++ b/app/views/case_logs/_tasklist.html.erb @@ -8,10 +8,13 @@