From 3efcb20e90f65ae0b079f5b6335226826c34122e Mon Sep 17 00:00:00 2001 From: David May-Miller Date: Tue, 8 Nov 2022 15:23:11 +0000 Subject: [PATCH] CLDC-1698 Update tenancy length validations to have a minimum of 1 year in most cases --- app/models/validations/tenancy_validations.rb | 38 +++++++++++++++++-- config/locales/en.yml | 4 +- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/app/models/validations/tenancy_validations.rb b/app/models/validations/tenancy_validations.rb index 25e09f205..d2fe27b63 100644 --- a/app/models/validations/tenancy_validations.rb +++ b/app/models/validations/tenancy_validations.rb @@ -5,7 +5,7 @@ module Validations::TenancyValidations def validate_fixed_term_tenancy(record) is_present = record.tenancylength.present? - is_in_range = record.tenancylength.to_i.between?(2, 99) + is_in_range = record.tenancylength.to_i.between?(min_tenancy_length(record), 99) conditions = [ { condition: !(record.is_secure_tenancy? || record.is_assured_shorthold_tenancy?) && is_present, @@ -13,11 +13,21 @@ module Validations::TenancyValidations }, { condition: (record.is_assured_shorthold_tenancy? && !is_in_range) && is_present, - error: I18n.t("validations.tenancy.length.shorthold"), + error: I18n.t( + "validations.tenancy.length.shorthold", + min_tenancy_length: min_tenancy_length(record), + rent_type: rent_type_mapping(record)[record.rent_type], + needs_type: needs_type_mapping[record.needstype] + ), }, { condition: record.is_secure_tenancy? && (!is_in_range && is_present), - error: I18n.t("validations.tenancy.length.secure"), + error: I18n.t( + "validations.tenancy.length.secure", + min_tenancy_length: min_tenancy_length(record), + rent_type: rent_type_mapping(record)[record.rent_type], + needs_type: needs_type_mapping[record.needstype] + ), }, ] @@ -41,4 +51,26 @@ module Validations::TenancyValidations record.errors.add :hhmemb, I18n.t("validations.tenancy.joint_more_than_one_member") end end + + def min_tenancy_length(record) + record.needstype == 2 || record.rent_type.in?([3, 5]) ? 1 : 2 + end + + def rent_type_mapping(record) + { + 1 => "Affordable Rent", + 2 => "London Affordable Rent", + 4 => "London Living Rent", + 3 => "Rent to Buy", + 0 => "Social Rent", + 5 => record.irproduct, + } + end + + def needs_type_mapping + { + 1 => "General needs", + 2 => "Supported housing", + } + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 003f573dc..80a9247cf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -301,8 +301,8 @@ en: tenancy: length: fixed_term_not_required: "You must only answer the length of the tenancy if it's fixed-term" - shorthold: "Enter a tenancy length between 2 and 99 years for a Fixed Term – Assured Shorthold Tenancy (AST)" - secure: "Enter a tenancy length between 2 and 99 years (or don't specify the length) for a Secure (including flexible) tenancy" + shorthold: "Enter a tenancy length between %{min_tenancy_length} and 99 years for a %{needs_type} %{rent_type} Fixed Term – Assured Shorthold Tenancy (AST)" + secure: "Enter a tenancy length between %{min_tenancy_length} and 99 years (or don't specify the length) for a %{needs_type} %{rent_type} Secure (including flexible) tenancy" internal_transfer: "Answer must be secure tenancy as this tenancy is an internal transfer" cannot_be_internal_transfer: "Answer cannot be internal transfer as this is not a secure tenancy" not_joint: "This cannot be a joint tenancy as you've told us there's only one person in the household"