Browse Source

CLDC-1698 Update tenancy length validations to have a minimum of 1 year in most cases

pull/975/head
David May-Miller 3 years ago
parent
commit
3efcb20e90
  1. 38
      app/models/validations/tenancy_validations.rb
  2. 4
      config/locales/en.yml

38
app/models/validations/tenancy_validations.rb

@ -5,7 +5,7 @@ module Validations::TenancyValidations
def validate_fixed_term_tenancy(record) def validate_fixed_term_tenancy(record)
is_present = record.tenancylength.present? 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 = [ conditions = [
{ {
condition: !(record.is_secure_tenancy? || record.is_assured_shorthold_tenancy?) && is_present, 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, 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), 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") record.errors.add :hhmemb, I18n.t("validations.tenancy.joint_more_than_one_member")
end end
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 end

4
config/locales/en.yml

@ -301,8 +301,8 @@ en:
tenancy: tenancy:
length: length:
fixed_term_not_required: "You must only answer the length of the tenancy if it's fixed-term" 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)" 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 2 and 99 years (or don't specify the length) for a Secure (including flexible) tenancy" 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" 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" 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" not_joint: "This cannot be a joint tenancy as you've told us there's only one person in the household"

Loading…
Cancel
Save