diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 066d9450c..79fb9ffb6 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -227,6 +227,10 @@ class CaseLog < ApplicationRecord prevten == 21 end + def is_reason_permanently_decanted? + reason == 1 + end + private PIO = Postcodes::IO.new diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index 3f410a007..67688794f 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -19,6 +19,11 @@ module Validations::HouseholdValidations record.errors.add :reason, I18n.t("validations.household.underoccupation_benefitcap.dont_know_required") end validate_other_field(record, 31, :reason, :other_reason_for_leaving_last_settled_home) + + if record.is_reason_permanently_decanted? && record.referral.present? && !record.is_internal_transfer? + record.errors.add :referral, I18n.t("validations.household.referral.reason_permanently_decanted") + record.errors.add :reason, I18n.t("validations.household.reason.not_internal_transfer") + end end def validate_armed_forces(record) diff --git a/config/locales/en.yml b/config/locales/en.yml index f73a277cd..a11768129 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -132,6 +132,7 @@ en: assessed_homeless: "Answer cannot be internal transfer as you already told us the tenant was assessed as homeless" other_homeless: "Answer cannot be internal transfer as you already told us the tenant was considered homeless by their landlord" prevten_invalid: "Answer cannot be internal transfer as you already told us the source of referral for this letting was %{prevten}" + reason_permanently_decanted: "Answer must be internal transfer as you already told us the tenant was permanently decanted from another property owned by this landlord" homeless: assessed: internal_transfer: "Answer cannot be assessed as homeless as you already told us this tenancy is an internal transfer" @@ -142,6 +143,8 @@ en: previous_la_known: "Enter a local authority" gender: male_refuge: "Answer cannot be refuge as the lead tenant identifies as male" + reason: + not_internal_transfer: "Answer cannot be permanently decanted from another property owned by this landlord as you told us the source of referral for this tenancy was not an internal transfer" tenancy: length: diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index b07e6adbb..b8a2dba23 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -229,6 +229,30 @@ RSpec.describe Validations::HouseholdValidations do expect(record.errors["reason"]).to be_empty end end + + context "when referral is not internal transfer" do + it "cannot be permanently decanted from another property owned by this landlord" do + record.reason = 1 + record.referral = 2 + household_validator.validate_reason_for_leaving_last_settled_home(record) + expect(record.errors["reason"]) + .to include(match(I18n.t("validations.household.reason.not_internal_transfer"))) + expect(record.errors["referral"]) + .to include(match(I18n.t("validations.household.referral.reason_permanently_decanted"))) + end + end + + context "when referral is internal transfer" do + it "can be permanently decanted from another property owned by this landlord" do + record.reason = 1 + record.referral = 1 + household_validator.validate_reason_for_leaving_last_settled_home(record) + expect(record.errors["reason"]) + .to be_empty + expect(record.errors["referral"]) + .to be_empty + end + end end describe "armed forces validations" do