From 13d67552c2a50469a65abc71884a898d485ad26c Mon Sep 17 00:00:00 2001 From: samyou-softwire Date: Mon, 9 Mar 2026 16:20:49 +0000 Subject: [PATCH] CLDC-4184: Consolidate logic for questions that appear in multiple subsections --- app/models/form/question.rb | 18 ++++++++++++++++-- .../form/sales/questions/deposit_amount.rb | 9 +++++---- app/models/form/sales/questions/equity.rb | 11 +++++++---- .../form/sales/questions/extra_borrowing.rb | 9 +++++---- .../sales/questions/has_leasehold_charges.rb | 9 +++++---- .../sales/questions/has_service_charge.rb | 17 +++++++---------- .../form/sales/questions/leasehold_charges.rb | 9 +++++---- .../sales/questions/living_before_purchase.rb | 5 +++-- .../questions/living_before_purchase_years.rb | 5 +++-- .../form/sales/questions/mortgage_amount.rb | 9 +++++---- .../form/sales/questions/mortgage_length.rb | 10 +++++----- .../sales/questions/mortgage_length_known.rb | 6 +++--- .../form/sales/questions/mortgageused.rb | 19 +++++++++---------- .../form/sales/questions/purchase_price.rb | 5 +++-- .../form/sales/questions/service_charge.rb | 17 +++++++---------- app/models/form/sales/questions/value.rb | 11 +++++++---- 16 files changed, 95 insertions(+), 74 deletions(-) diff --git a/app/models/form/question.rb b/app/models/form/question.rb index b3e7a36f7..1bd915149 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -373,8 +373,22 @@ private # every year currently visible should have an explicit question number specified. # however, form_handler.rb will still initialise the next form even if its not visible. # so we have a fallback to the latest year for these future years so all question have a question number. - def get_question_number_from_hash(hash) - hash[form.start_date.year] || hash[hash.keys.max] + # + # some hashes are complex and require a second key to find the correct year. + # 2025 and before the question number used to depend on the ownershipsch and other log attributes + # 2026 and beyond we use the subsection ID for consistency + def get_question_number_from_hash(hash, value_key: nil) + year = if hash[form.start_date.year].present? + form.start_date.year + else + hash.keys.max + end + + hash_value = hash[year] + + return hash_value if hash_value.is_a?(Integer) + + hash_value[value_key] end RADIO_YES_VALUE = { diff --git a/app/models/form/sales/questions/deposit_amount.rb b/app/models/form/sales/questions/deposit_amount.rb index ede6335e1..667dfae29 100644 --- a/app/models/form/sales/questions/deposit_amount.rb +++ b/app/models/form/sales/questions/deposit_amount.rb @@ -1,6 +1,6 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question - def initialize(id, hsh, subsection, ownershipsch:, optional:) - super(id, hsh, subsection) + def initialize(id, hsh, page, ownershipsch:, optional:) + super(id, hsh, page) @id = "deposit" @type = "numeric" @min = 0 @@ -9,7 +9,7 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question @width = 5 @prefix = "£" @ownershipsch = ownershipsch - @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: form.start_year_2026_or_later? ? subsection.id : ownershipsch) @optional = optional @top_guidance_partial = top_guidance_partial @copy_key = copy_key @@ -20,10 +20,11 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question log.outright_sale? && !log.mortgage_used? end - QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { 2023 => { 1 => 95, 2 => 108, 3 => 116 }, 2024 => { 1 => 96, 2 => 109, 3 => 116 }, 2025 => { 1 => 85, 2 => 110 }, + 2026 => { "shared_ownership_initial_purchase" => 85, "discounted_ownership_scheme" => 110 }, }.freeze def top_guidance_partial diff --git a/app/models/form/sales/questions/equity.rb b/app/models/form/sales/questions/equity.rb index a2539b968..33f90ccf4 100644 --- a/app/models/form/sales/questions/equity.rb +++ b/app/models/form/sales/questions/equity.rb @@ -9,11 +9,14 @@ class Form::Sales::Questions::Equity < ::Form::Question @step = 0.1 @width = 5 @suffix = "%" - @question_number = question_number_from_year[form.start_date.year] || question_number_from_year[question_number_from_year.keys.max] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: subsection.id) @top_guidance_partial = "financial_calculations_shared_ownership" end - def question_number_from_year - { 2023 => 89, 2024 => 90, 2025 => subsection.id == "shared_ownership_staircasing_transaction" ? 98 : 81 } - end + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { + 2023 => 89, + 2024 => 90, + 2025 => { "shared_ownership_initial_purchase" => 81, "shared_ownership_staircasing_transaction" => 98 }, + 2026 => { "shared_ownership_initial_purchase" => 81, "shared_ownership_staircasing_transaction" => 98 }, + }.freeze end diff --git a/app/models/form/sales/questions/extra_borrowing.rb b/app/models/form/sales/questions/extra_borrowing.rb index 288ddb107..9836d245e 100644 --- a/app/models/form/sales/questions/extra_borrowing.rb +++ b/app/models/form/sales/questions/extra_borrowing.rb @@ -1,12 +1,12 @@ class Form::Sales::Questions::ExtraBorrowing < ::Form::Question - def initialize(id, hsh, subsection, ownershipsch:) - super(id, hsh, subsection) + def initialize(id, hsh, page, ownershipsch:) + super(id, hsh, page) @id = "extrabor" @type = "radio" @answer_options = ANSWER_OPTIONS @page = page @ownershipsch = ownershipsch - @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: form.start_year_2026_or_later? ? subsection.id : ownershipsch) end ANSWER_OPTIONS = { @@ -16,9 +16,10 @@ class Form::Sales::Questions::ExtraBorrowing < ::Form::Question "3" => { "value" => "Don’t know" }, }.freeze - QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { 2023 => { 1 => 94, 2 => 107, 3 => 115 }, 2024 => { 1 => 95, 2 => 108, 3 => 115 }, 2025 => { 2 => 109 }, + 2026 => { "discounted_ownership_scheme" => 109 }, }.freeze end diff --git a/app/models/form/sales/questions/has_leasehold_charges.rb b/app/models/form/sales/questions/has_leasehold_charges.rb index 36086ea36..667ed6ee4 100644 --- a/app/models/form/sales/questions/has_leasehold_charges.rb +++ b/app/models/form/sales/questions/has_leasehold_charges.rb @@ -1,6 +1,6 @@ class Form::Sales::Questions::HasLeaseholdCharges < ::Form::Question - def initialize(id, hsh, subsection, ownershipsch:) - super(id, hsh, subsection) + def initialize(id, hsh, page, ownershipsch:) + super(id, hsh, page) @id = "has_mscharge" @type = "radio" @answer_options = ANSWER_OPTIONS @@ -16,7 +16,7 @@ class Form::Sales::Questions::HasLeaseholdCharges < ::Form::Question } @ownershipsch = ownershipsch @copy_key = "sales.sale_information.leaseholdcharges.has_mscharge" - @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: form.start_year_2026_or_later? ? subsection.id : ownershipsch) end ANSWER_OPTIONS = { @@ -24,8 +24,9 @@ class Form::Sales::Questions::HasLeaseholdCharges < ::Form::Question "0" => { "value" => "No" }, }.freeze - QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { 2024 => { 1 => 99, 2 => 110, 3 => 117 }, 2025 => { 2 => 111 }, + 2026 => 111, }.freeze end diff --git a/app/models/form/sales/questions/has_service_charge.rb b/app/models/form/sales/questions/has_service_charge.rb index 708c32f0d..205af5328 100644 --- a/app/models/form/sales/questions/has_service_charge.rb +++ b/app/models/form/sales/questions/has_service_charge.rb @@ -1,6 +1,6 @@ class Form::Sales::Questions::HasServiceCharge < ::Form::Question - def initialize(id, hsh, subsection, staircasing:) - super(id, hsh, subsection) + def initialize(id, hsh, page, staircasing:) + super(id, hsh, page) @id = "has_mscharge" @type = "radio" @answer_options = ANSWER_OPTIONS @@ -16,7 +16,7 @@ class Form::Sales::Questions::HasServiceCharge < ::Form::Question } @copy_key = "sales.sale_information.servicecharges.has_servicecharge" @staircasing = staircasing - @question_number = question_number_from_year[form.start_date.year] || question_number_from_year[question_number_from_year.keys.max] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: subsection.id) end ANSWER_OPTIONS = { @@ -24,11 +24,8 @@ class Form::Sales::Questions::HasServiceCharge < ::Form::Question "0" => { "value" => "No" }, }.freeze - def question_number_from_year - if @staircasing - { 2026 => 0 }.freeze - else - { 2025 => 88, 2026 => 0 }.freeze - end - end + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { + 2025 => 88, + 2026 => { "shared_ownership_initial_purchase" => 88, "shared_ownership_staircasing_transaction" => 88 }, + } end diff --git a/app/models/form/sales/questions/leasehold_charges.rb b/app/models/form/sales/questions/leasehold_charges.rb index e524bfa00..6606491c1 100644 --- a/app/models/form/sales/questions/leasehold_charges.rb +++ b/app/models/form/sales/questions/leasehold_charges.rb @@ -1,6 +1,6 @@ class Form::Sales::Questions::LeaseholdCharges < ::Form::Question - def initialize(id, hsh, subsection, ownershipsch:) - super(id, hsh, subsection) + def initialize(id, hsh, page, ownershipsch:) + super(id, hsh, page) @id = "mscharge" @type = "numeric" @min = 1 @@ -9,13 +9,14 @@ class Form::Sales::Questions::LeaseholdCharges < ::Form::Question @prefix = "£" @copy_key = "sales.sale_information.leaseholdcharges.mscharge" @ownershipsch = ownershipsch - @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: form.start_year_2026_or_later? ? subsection.id : ownershipsch) @strip_commas = true end - QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { 2023 => { 1 => 98, 2 => 109, 3 => 117 }, 2024 => { 1 => 99, 2 => 110, 3 => 117 }, 2025 => { 2 => 111 }, + 2026 => { "discounted_ownership_scheme" => 111 }, }.freeze end diff --git a/app/models/form/sales/questions/living_before_purchase.rb b/app/models/form/sales/questions/living_before_purchase.rb index 06ff095d1..1a47f27a5 100644 --- a/app/models/form/sales/questions/living_before_purchase.rb +++ b/app/models/form/sales/questions/living_before_purchase.rb @@ -16,7 +16,7 @@ class Form::Sales::Questions::LivingBeforePurchase < ::Form::Question ], } @ownershipsch = ownershipsch - @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: form.start_year_2026_or_later? ? subsection.id : ownershipsch) end ANSWER_OPTIONS = { @@ -24,9 +24,10 @@ class Form::Sales::Questions::LivingBeforePurchase < ::Form::Question "1" => { "value" => "No" }, }.freeze - QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { 2023 => { 1 => 75, 2 => 99 }, 2024 => { 1 => 77, 2 => 100 }, 2025 => { 1 => 75, 2 => 102 }, + 2026 => { "shared_ownership_initial_purchase" => 75, "discounted_ownership_scheme" => 102 }, }.freeze end diff --git a/app/models/form/sales/questions/living_before_purchase_years.rb b/app/models/form/sales/questions/living_before_purchase_years.rb index 010aa6edc..b34245a78 100644 --- a/app/models/form/sales/questions/living_before_purchase_years.rb +++ b/app/models/form/sales/questions/living_before_purchase_years.rb @@ -9,16 +9,17 @@ class Form::Sales::Questions::LivingBeforePurchaseYears < ::Form::Question @step = 1 @width = 5 @ownershipsch = ownershipsch - @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: form.start_year_2026_or_later? ? subsection.id : ownershipsch) end def suffix_label(log) " #{'year'.pluralize(log[id])}" end - QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { 2023 => { 1 => 75, 2 => 99 }, 2024 => { 1 => 77, 2 => 100 }, 2025 => { 1 => 75, 2 => 102 }, + 2026 => { "shared_ownership_initial_purchase" => 75, "discounted_ownership_scheme" => 102 }, }.freeze end diff --git a/app/models/form/sales/questions/mortgage_amount.rb b/app/models/form/sales/questions/mortgage_amount.rb index a61dce8f3..5adc29731 100644 --- a/app/models/form/sales/questions/mortgage_amount.rb +++ b/app/models/form/sales/questions/mortgage_amount.rb @@ -1,6 +1,6 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question - def initialize(id, hsh, subsection, ownershipsch:) - super(id, hsh, subsection) + def initialize(id, hsh, page, ownershipsch:) + super(id, hsh, page) @id = "mortgage" @type = "numeric" @min = 1 @@ -8,15 +8,16 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question @width = 5 @prefix = "£" @ownershipsch = ownershipsch - @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: form.start_year_2026_or_later? ? subsection.id : ownershipsch) @top_guidance_partial = top_guidance_partial @strip_commas = true end - QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { 2023 => { 1 => 91, 2 => 104, 3 => 112 }, 2024 => { 1 => 92, 2 => 105, 3 => 113 }, 2025 => { 1 => 83, 2 => 107 }, + 2026 => { "shared_ownership_initial_purchase" => 83, "discounted_ownership_scheme" => 107 }, }.freeze def derived?(log) diff --git a/app/models/form/sales/questions/mortgage_length.rb b/app/models/form/sales/questions/mortgage_length.rb index 493deb11d..99c077955 100644 --- a/app/models/form/sales/questions/mortgage_length.rb +++ b/app/models/form/sales/questions/mortgage_length.rb @@ -1,6 +1,6 @@ class Form::Sales::Questions::MortgageLength < ::Form::Question - def initialize(id, hsh, subsection, ownershipsch:) - super(id, hsh, subsection) + def initialize(id, hsh, page, ownershipsch:) + super(id, hsh, page) @id = "mortlen" @type = "numeric" @min = 0 @@ -8,17 +8,17 @@ class Form::Sales::Questions::MortgageLength < ::Form::Question @step = 1 @width = 5 @ownershipsch = ownershipsch - @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: form.start_year_2026_or_later? ? subsection.id : ownershipsch) end def suffix_label(log) " #{'year'.pluralize(log[id])}" end - QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { 2023 => { 1 => 93, 2 => 106, 3 => 114 }, 2024 => { 1 => 94, 2 => 107, 3 => 114 }, 2025 => { 1 => 84, 2 => 108 }, - 2026 => { 1 => 84, 2 => 108 }, + 2026 => { "shared_ownership_initial_purchase" => 84, "discounted_ownership_scheme" => 108 }, }.freeze end diff --git a/app/models/form/sales/questions/mortgage_length_known.rb b/app/models/form/sales/questions/mortgage_length_known.rb index 5d2598771..fa21ce277 100644 --- a/app/models/form/sales/questions/mortgage_length_known.rb +++ b/app/models/form/sales/questions/mortgage_length_known.rb @@ -10,12 +10,12 @@ class Form::Sales::Questions::MortgageLengthKnown < ::Form::Question { "mortlen_known" => 0 }, ], } - @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: form.start_year_2026_or_later? ? subsection.id : ownershipsch) end ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze - QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { - 2026 => { 1 => 84, 2 => 108 }, + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { + 2026 => { "shared_ownership_initial_purchase" => 84, "discounted_ownership_scheme" => 108 }, }.freeze end diff --git a/app/models/form/sales/questions/mortgageused.rb b/app/models/form/sales/questions/mortgageused.rb index fc5818886..618216cb6 100644 --- a/app/models/form/sales/questions/mortgageused.rb +++ b/app/models/form/sales/questions/mortgageused.rb @@ -1,11 +1,11 @@ class Form::Sales::Questions::Mortgageused < ::Form::Question - def initialize(id, hsh, subsection, ownershipsch:) - super(id, hsh, subsection) + def initialize(id, hsh, page, ownershipsch:) + super(id, hsh, page) @id = "mortgageused" @type = "radio" @answer_options = ANSWER_OPTIONS @ownershipsch = ownershipsch - @question_number = question_number_from_year_and_ownership.fetch(form.start_date.year, question_number_from_year_and_ownership.max_by { |k, _v| k }.last)[ownershipsch] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: form.start_year_2025_or_later? ? subsection.id : ownershipsch) @top_guidance_partial = top_guidance_partial end @@ -30,13 +30,12 @@ class Form::Sales::Questions::Mortgageused < ::Form::Question ANSWER_OPTIONS.reject { |key, _v| %w[3 divider].include?(key) } end - def question_number_from_year_and_ownership - { - 2023 => { 1 => 90, 2 => 103, 3 => 111 }, - 2024 => { 1 => 91, 2 => 104, 3 => 112 }, - 2025 => { 1 => subsection.id == "shared_ownership_staircasing_transaction" ? 99 : 82, 2 => 106 }, - } - end + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { + 2023 => { 1 => 90, 2 => 103, 3 => 111 }, + 2024 => { 1 => 91, 2 => 104, 3 => 112 }, + 2025 => { "shared_ownership_initial_purchase" => 82, "shared_ownership_staircasing_transaction" => 99, "discounted_ownership_scheme" => 106 }, + 2026 => { "shared_ownership_initial_purchase" => 82, "shared_ownership_staircasing_transaction" => 99, "discounted_ownership_scheme" => 106 }, + }.freeze def top_guidance_partial return "financial_calculations_shared_ownership" if @ownershipsch == 1 diff --git a/app/models/form/sales/questions/purchase_price.rb b/app/models/form/sales/questions/purchase_price.rb index d37d549ce..74357f935 100644 --- a/app/models/form/sales/questions/purchase_price.rb +++ b/app/models/form/sales/questions/purchase_price.rb @@ -8,15 +8,16 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question @width = 5 @prefix = "£" @ownership_sch = ownershipsch - @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: form.start_year_2026_or_later? ? subsection.id : ownershipsch) @top_guidance_partial = top_guidance_partial @strip_commas = true end - QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { 2023 => { 2 => 100, 3 => 110 }, 2024 => { 2 => 101, 3 => 111 }, 2025 => { 2 => 103 }, + 2026 => { "discounted_ownership_scheme" => 103 }, }.freeze def copy_key diff --git a/app/models/form/sales/questions/service_charge.rb b/app/models/form/sales/questions/service_charge.rb index f3aec4a2b..300d13973 100644 --- a/app/models/form/sales/questions/service_charge.rb +++ b/app/models/form/sales/questions/service_charge.rb @@ -1,6 +1,6 @@ class Form::Sales::Questions::ServiceCharge < ::Form::Question - def initialize(id, hsh, subsection, staircasing:) - super(id, hsh, subsection) + def initialize(id, hsh, page, staircasing:) + super(id, hsh, page) @id = "mscharge" @type = "numeric" @min = 1 @@ -10,15 +10,12 @@ class Form::Sales::Questions::ServiceCharge < ::Form::Question @prefix = "£" @copy_key = "sales.sale_information.servicecharges.servicecharge" @staircasing = staircasing - @question_number = question_number_from_year[form.start_date.year] || question_number_from_year[question_number_from_year.keys.max] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: subsection.id) @strip_commas = true end - def question_number_from_year - if @staircasing - { 2026 => 0 }.freeze - else - { 2025 => 88, 2026 => 0 }.freeze - end - end + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { + 2025 => 88, + 2026 => { "shared_ownership_initial_purchase" => 88, "shared_ownership_staircasing_transaction" => 88 }, + } end diff --git a/app/models/form/sales/questions/value.rb b/app/models/form/sales/questions/value.rb index c8b9cadd3..fc1db2405 100644 --- a/app/models/form/sales/questions/value.rb +++ b/app/models/form/sales/questions/value.rb @@ -8,12 +8,15 @@ class Form::Sales::Questions::Value < ::Form::Question @step = 1 @width = 5 @prefix = "£" - @question_number = question_number_from_year[form.start_date.year] || question_number_from_year[question_number_from_year.keys.max] + @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR_AND_SECTION, value_key: subsection.id) @top_guidance_partial = "financial_calculations_shared_ownership" @strip_commas = true end - def question_number_from_year - { 2023 => 88, 2024 => 89, 2025 => subsection.id == "shared_ownership_staircasing_transaction" ? 97 : 80 } - end + QUESTION_NUMBER_FROM_YEAR_AND_SECTION = { + 2023 => 88, + 2024 => 89, + 2025 => { "shared_ownership_initial_purchase" => 80, "shared_ownership_staircasing_transaction" => 97 }, + 2026 => { "shared_ownership_initial_purchase" => 80, "shared_ownership_staircasing_transaction" => 97 }, + }.freeze end