From 9103e5d5adeca6c8ded021d699a255907977e489 Mon Sep 17 00:00:00 2001 From: oscar-richardson-softwire Date: Thu, 12 Feb 2026 10:00:09 +0000 Subject: [PATCH] Add functionality --- .../pages/tenancyother_value_check.rb | 24 +++++++++++++++++++ .../questions/tenancyother_value_check.rb | 13 ++++++++++ .../subsections/tenancy_information.rb | 1 + app/models/validations/soft_validations.rb | 10 ++++++++ .../2026/lettings/soft_validations.en.yml | 10 ++++++++ ...nancyother_value_check_to_lettings_logs.rb | 5 ++++ db/schema.rb | 3 ++- 7 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 app/models/form/lettings/pages/tenancyother_value_check.rb create mode 100644 app/models/form/lettings/questions/tenancyother_value_check.rb create mode 100644 db/migrate/20260212091506_add_tenancyother_value_check_to_lettings_logs.rb diff --git a/app/models/form/lettings/pages/tenancyother_value_check.rb b/app/models/form/lettings/pages/tenancyother_value_check.rb new file mode 100644 index 000000000..e350da85c --- /dev/null +++ b/app/models/form/lettings/pages/tenancyother_value_check.rb @@ -0,0 +1,24 @@ +class Form::Lettings::Pages::TenancyotherValueCheck < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "tenancyother_value_check" + @copy_key = "lettings.soft_validations.tenancyother_value_check" + @depends_on = [{ "tenancyother_might_be_introductory_or_starter_period?" => true }] + @title_text = { + "translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text", + "arguments" => [{ "key" => "tenancyother", "i18n_template" => "tenancyother" }], + } + @informative_text = { + "translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text", + "arguments" => [], + } + end + + def questions + @questions ||= [Form::Lettings::Questions::TenancyotherValueCheck.new(nil, nil, self)] + end + + def interruption_screen_question_ids + %w[tenancy tenancyother] + end +end diff --git a/app/models/form/lettings/questions/tenancyother_value_check.rb b/app/models/form/lettings/questions/tenancyother_value_check.rb new file mode 100644 index 000000000..309de7169 --- /dev/null +++ b/app/models/form/lettings/questions/tenancyother_value_check.rb @@ -0,0 +1,13 @@ +class Form::Lettings::Questions::TenancyotherValueCheck < ::Form::Question + def initialize(id, hsh, page) + super + @id = "tenancyother_value_check" + @copy_key = "lettings.soft_validations.tenancyother_value_check" + @type = "interruption_screen" + @check_answers_card_number = 0 + @answer_options = ANSWER_OPTIONS + @hidden_in_check_answers = { "depends_on" => [{ "tenancyother_value_check" => 0 }, { "tenancyother_value_check" => 1 }] } + end + + ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze +end diff --git a/app/models/form/lettings/subsections/tenancy_information.rb b/app/models/form/lettings/subsections/tenancy_information.rb index b65039b8d..51c58fec5 100644 --- a/app/models/form/lettings/subsections/tenancy_information.rb +++ b/app/models/form/lettings/subsections/tenancy_information.rb @@ -13,6 +13,7 @@ class Form::Lettings::Subsections::TenancyInformation < ::Form::Subsection Form::Lettings::Pages::TenancyType.new(nil, nil, self), Form::Lettings::Pages::StarterTenancyType.new(nil, nil, self), Form::Lettings::Pages::TenancyLength.new(nil, nil, self), + (Form::Lettings::Pages::TenancyotherValueCheck.new(nil, nil, self) if form.start_year_2026_or_later?), Form::Lettings::Pages::TenancyLengthAffordableRent.new(nil, nil, self), Form::Lettings::Pages::TenancyLengthIntermediateRent.new(nil, nil, self), (Form::Lettings::Pages::TenancyLengthPeriodic.new(nil, nil, self) if form.start_year_2024_or_later?), diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index 35436dc32..536101062 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -208,6 +208,16 @@ module Validations::SoftValidations PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY_REGEX.match?(reasonother) end + PHRASES_LIKELY_TO_INDICATE_INTRODUCTORY_OR_STARTER_PERIOD = %w[introductory intro starter].freeze + + PHRASES_LIKELY_TO_INDICATE_INTRODUCTORY_OR_STARTER_PERIOD_REGEX = Regexp.union( + PHRASES_LIKELY_TO_INDICATE_INTRODUCTORY_OR_STARTER_PERIOD.map { |phrase| Regexp.new("\\b[^[:alpha]]*#{phrase}[^[:alpha:]]*\\b", Regexp::IGNORECASE) }, + ) + + def tenancyother_might_be_introductory_or_starter_period? + PHRASES_LIKELY_TO_INDICATE_INTRODUCTORY_OR_STARTER_PERIOD_REGEX.match?(tenancyother) + end + def multiple_partners? return unless hhmemb diff --git a/config/locales/forms/2026/lettings/soft_validations.en.yml b/config/locales/forms/2026/lettings/soft_validations.en.yml index a2fe12a1f..9007360ac 100644 --- a/config/locales/forms/2026/lettings/soft_validations.en.yml +++ b/config/locales/forms/2026/lettings/soft_validations.en.yml @@ -57,6 +57,16 @@ en: title_text: "You told us that the tenant’s main reason for leaving their last settled home was %{reasonother}." informative_text: "The reason you have entered looks very similar to one of the existing response categories. Please check the categories and select the appropriate one. If the existing categories are not suitable, please confirm here to move onto the next question." + tenancyother_value_check: + page_header: "" + check_answer_label: "Tenancy other confirmation" + check_answer_prompt: "Confirm tenancy type" + hint_text: "" + question_text: "" + title_text: "You told us that the type of tenancy was %{tenancyother}." + informative_text: "Give the type of tenancy that the tenants rolls onto after any introductory or starter period." + + referral_value_check: page_header: "" check_answer_label: "Referral confirmation" diff --git a/db/migrate/20260212091506_add_tenancyother_value_check_to_lettings_logs.rb b/db/migrate/20260212091506_add_tenancyother_value_check_to_lettings_logs.rb new file mode 100644 index 000000000..339dc7a07 --- /dev/null +++ b/db/migrate/20260212091506_add_tenancyother_value_check_to_lettings_logs.rb @@ -0,0 +1,5 @@ +class AddTenancyotherValueCheckToLettingsLogs < ActiveRecord::Migration[7.0] + def change + add_column :lettings_logs, :tenancyother_value_check, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 6fd081249..edb31db8e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2026_01_28_121417) do +ActiveRecord::Schema[7.2].define(version: 2026_02_12_091506) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -384,6 +384,7 @@ ActiveRecord::Schema[7.2].define(version: 2026_01_28_121417) do t.string "sexrab6" t.string "sexrab7" t.string "sexrab8" + t.integer "tenancyother_value_check" t.index ["assigned_to_id"], name: "index_lettings_logs_on_assigned_to_id" t.index ["bulk_upload_id"], name: "index_lettings_logs_on_bulk_upload_id" t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id"