diff --git a/app/models/case_log.rb b/app/models/case_log.rb index a24bc8a7b..94589db0d 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -124,6 +124,10 @@ class CaseLog < ApplicationRecord net_income_in_soft_min_range? || net_income_in_soft_max_range? end + def rent_in_soft_validation_range? + rent_in_soft_min_range? || rent_in_soft_max_range? + end + def given_reasonable_preference? reasonpref == 1 end diff --git a/app/models/form.rb b/app/models/form.rb index c0f5243fd..cd3c5a972 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -37,7 +37,7 @@ class Form def next_page(page, case_log) page_ids = subsection_for_page(page).pages.map(&:id) page_index = page_ids.index(page.id) - page_id = page.id.include?("value_check") && case_log[page.id] == 1 ? page_ids[page_index - 1] : page_ids[page_index + 1] + page_id = page.id.include?("value_check") && case_log[page.questions[0].id] == 1 ? previous_page(page_ids, page_index, case_log) : page_ids[page_index + 1] nxt_page = get_page(page_id) return :check_answers if nxt_page.nil? @@ -144,4 +144,11 @@ class Form subsection_ids = subsections.map(&:id) subsection.id == subsection_ids[subsection_ids.length - 1] && next_page(page, case_log) == :check_answers end + + def previous_page(page_ids, page_index, case_log) + prev_page = get_page(page_ids[page_index - 1]) + return prev_page.id if prev_page.routed_to?(case_log) + + previous_page(page_ids, page_index - 1, case_log) + end end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 6d8c269b3..68438ab41 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -4573,7 +4573,7 @@ } } }, - "check_income_amount": { + "net_income_value_check": { "depends_on": [{ "net_income_soft_validation_triggered?": true }], "title_text": "Net income is outside the expected range based on the main tenant’s working situation", "informative_text": { @@ -5568,33 +5568,9 @@ } ] }, - "check_min_rent_amount": { - "depends_on": [{ "rent_in_soft_min_range?": true }], - "title_text": "Rent value is under the expected range", - "informative_text": { - "translation": "soft_validations.rent.min_max.hint_text", - "argument": ["brent"] - }, - "questions": { - "rent_value_check": { - "check_answer_label": "Rent soft validation", - "hidden_in_check_answers": true, - "header": "Are you sure this is correct?", - "type": "interruption_screen", - "answer_options": { - "0": { - "value":"Yes" - }, - "1": { - "value":"No" - } - } - } - } - }, - "check_max_rent_amount": { - "depends_on": [{ "rent_in_soft_max_range?": true }], - "title_text": "Rent value is over the expected range", + "rent_value_check": { + "depends_on": [{ "rent_in_soft_validation_range?": true }], + "title_text": "Rent value is outside of the expected range", "informative_text": { "translation": "soft_validations.rent.min_max.hint_text", "argument": ["brent"] diff --git a/db/migrate/20220328133331_add_rent_value_check.rb b/db/migrate/20220328133331_add_rent_value_check.rb index 4ac83f7c7..c06b0dbd7 100644 --- a/db/migrate/20220328133331_add_rent_value_check.rb +++ b/db/migrate/20220328133331_add_rent_value_check.rb @@ -1,5 +1,5 @@ class AddRentValueCheck < ActiveRecord::Migration[7.0] def change - add_column :case_logs, :rent_value_check, :boolean + add_column :case_logs, :rent_value_check, :integer end end diff --git a/db/schema.rb b/db/schema.rb index 966aa74be..c1bed2e41 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -231,7 +231,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do t.string "relat6" t.string "relat7" t.string "relat8" - t.boolean "rent_value_check" + t.integer "rent_value_check" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id" end