diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index 70c51f478..8cabf1ce5 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -157,6 +157,9 @@ module DerivedVariables::LettingsLogVariables self.is_la_inferred = false end + self.referral = 7 if referral_type == 6 + self.referral = 16 if referral_type == 7 + reset_address_fields! if is_supported_housing? set_checkbox_values! diff --git a/app/models/form/lettings/pages/referral_direct.rb b/app/models/form/lettings/pages/referral_direct.rb new file mode 100644 index 000000000..df05aa997 --- /dev/null +++ b/app/models/form/lettings/pages/referral_direct.rb @@ -0,0 +1,11 @@ +class Form::Lettings::Pages::ReferralDirect < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "referral_direct" + @depends_on = [{ "referral_type" => 1 }] + end + + def questions + @questions ||= [Form::Lettings::Questions::ReferralDirect.new(nil, nil, self)] + end +end diff --git a/app/models/form/lettings/pages/referral.rb b/app/models/form/lettings/pages/referral_general_needs.rb similarity index 64% rename from app/models/form/lettings/pages/referral.rb rename to app/models/form/lettings/pages/referral_general_needs.rb index 8b6fcadbb..5522d1f23 100644 --- a/app/models/form/lettings/pages/referral.rb +++ b/app/models/form/lettings/pages/referral_general_needs.rb @@ -1,4 +1,4 @@ -class Form::Lettings::Pages::Referral < ::Form::Page +class Form::Lettings::Pages::ReferralGeneralNeeds < ::Form::Page def initialize(id, hsh, subsection) super @id = "referral" @@ -7,6 +7,6 @@ class Form::Lettings::Pages::Referral < ::Form::Page end def questions - @questions ||= [Form::Lettings::Questions::Referral.new(nil, nil, self)] + @questions ||= [Form::Lettings::Questions::ReferralGeneralNeeds.new(nil, nil, self)] end end diff --git a/app/models/form/lettings/pages/referral_general_needs_prp.rb b/app/models/form/lettings/pages/referral_general_needs_prp.rb new file mode 100644 index 000000000..e3206ebdb --- /dev/null +++ b/app/models/form/lettings/pages/referral_general_needs_prp.rb @@ -0,0 +1,12 @@ +class Form::Lettings::Pages::ReferralGeneralNeedsPrp < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "referral_prp" + @copy_key = "lettings.household_situation.referral.general_needs.prp" + @depends_on = [{ "owning_organisation_provider_type" => "PRP", "needstype" => 1, "renewal" => 0 }] + end + + def questions + @questions ||= [Form::Lettings::Questions::ReferralGeneralNeedsPrp.new(nil, nil, self)] + end +end diff --git a/app/models/form/lettings/pages/referral_hsc.rb b/app/models/form/lettings/pages/referral_hsc.rb new file mode 100644 index 000000000..596852947 --- /dev/null +++ b/app/models/form/lettings/pages/referral_hsc.rb @@ -0,0 +1,11 @@ +class Form::Lettings::Pages::ReferralHsc < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "referral_hsc" + @depends_on = [{ "referral_type" => 4 }] + end + + def questions + @questions ||= [Form::Lettings::Questions::ReferralHsc.new(nil, nil, self)] + end +end diff --git a/app/models/form/lettings/pages/referral_justice.rb b/app/models/form/lettings/pages/referral_justice.rb new file mode 100644 index 000000000..fa10bb727 --- /dev/null +++ b/app/models/form/lettings/pages/referral_justice.rb @@ -0,0 +1,11 @@ +class Form::Lettings::Pages::ReferralJustice < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "referral_justice" + @depends_on = [{ "referral_type" => 5 }] + end + + def questions + @questions ||= [Form::Lettings::Questions::ReferralJustice.new(nil, nil, self)] + end +end diff --git a/app/models/form/lettings/pages/referral_la.rb b/app/models/form/lettings/pages/referral_la.rb new file mode 100644 index 000000000..3f04f3aaf --- /dev/null +++ b/app/models/form/lettings/pages/referral_la.rb @@ -0,0 +1,11 @@ +class Form::Lettings::Pages::ReferralLa < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "referral_la" + @depends_on = [{ "referral_type" => 2 }] + end + + def questions + @questions ||= [Form::Lettings::Questions::ReferralLa.new(nil, nil, self)] + end +end diff --git a/app/models/form/lettings/pages/referral_prp.rb b/app/models/form/lettings/pages/referral_prp.rb index baeb01784..8d25edc44 100644 --- a/app/models/form/lettings/pages/referral_prp.rb +++ b/app/models/form/lettings/pages/referral_prp.rb @@ -2,8 +2,7 @@ class Form::Lettings::Pages::ReferralPrp < ::Form::Page def initialize(id, hsh, subsection) super @id = "referral_prp" - @copy_key = "lettings.household_situation.referral.general_needs.prp" - @depends_on = [{ "owning_organisation_provider_type" => "PRP", "needstype" => 1, "renewal" => 0 }] + @depends_on = [{ "referral_type" => 3 }] end def questions diff --git a/app/models/form/lettings/pages/referral_type.rb b/app/models/form/lettings/pages/referral_type.rb new file mode 100644 index 000000000..3cca2ca2b --- /dev/null +++ b/app/models/form/lettings/pages/referral_type.rb @@ -0,0 +1,10 @@ +class Form::Lettings::Pages::ReferralType < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "referral_type" + end + + def questions + @questions ||= [Form::Lettings::Questions::ReferralType.new(nil, nil, self)] + end +end diff --git a/app/models/form/lettings/questions/referral_direct.rb b/app/models/form/lettings/questions/referral_direct.rb new file mode 100644 index 000000000..ddadcc8b7 --- /dev/null +++ b/app/models/form/lettings/questions/referral_direct.rb @@ -0,0 +1,26 @@ +class Form::Lettings::Questions::ReferralDirect < ::Form::Question + def initialize(id, hsh, page) + super + @id = "referral" + @copy_key = "lettings.household_situation.referral.direct" + @type = "radio" + @check_answers_card_number = 0 + @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + end + + def answer_options + { + "20" => { + "value" => "Homeless households owed a duty and not on a housing register or waiting list", + }, + "2" => { + "value" => "Tenant applied directly for an available property", + }, + "8" => { + "value" => "Relocated through official housing mobility scheme", + }, + }.freeze + end + + QUESTION_NUMBER_FROM_YEAR = { 2025 => 84 }.freeze +end diff --git a/app/models/form/lettings/questions/referral.rb b/app/models/form/lettings/questions/referral_general_needs.rb similarity index 97% rename from app/models/form/lettings/questions/referral.rb rename to app/models/form/lettings/questions/referral_general_needs.rb index 98e5a9186..6efdfc1f0 100644 --- a/app/models/form/lettings/questions/referral.rb +++ b/app/models/form/lettings/questions/referral_general_needs.rb @@ -1,4 +1,4 @@ -class Form::Lettings::Questions::Referral < ::Form::Question +class Form::Lettings::Questions::ReferralGeneralNeeds < ::Form::Question def initialize(id, hsh, page) super @id = "referral" diff --git a/app/models/form/lettings/questions/referral_general_needs_prp.rb b/app/models/form/lettings/questions/referral_general_needs_prp.rb new file mode 100644 index 000000000..afd26117b --- /dev/null +++ b/app/models/form/lettings/questions/referral_general_needs_prp.rb @@ -0,0 +1,105 @@ +class Form::Lettings::Questions::ReferralGeneralNeedsPrp < ::Form::Question + def initialize(id, hsh, page) + super + @id = "referral" + @copy_key = "lettings.household_situation.referral.general_needs.prp" + @type = "radio" + @check_answers_card_number = 0 + @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + end + + def answer_options + if form.start_year_2024_or_later? + { + "1" => { + "value" => "Internal transfer", + "hint" => "Where the tenant has moved to another social property owned by the same landlord.", + }, + "2" => { + "value" => "Tenant applied directly (no referral or nomination)", + }, + "3" => { + "value" => "Nominated by a local housing authority", + }, + "8" => { + "value" => "Re-located through official housing mobility scheme", + }, + "10" => { + "value" => "Other social landlord", + }, + "9" => { + "value" => "Community learning disability team", + }, + "14" => { + "value" => "Community mental health team", + }, + "15" => { + "value" => "Health service", + }, + "18" => { + "value" => "Police, probation, prison or youth offending team – tenant had custodial sentence", + }, + "19" => { + "value" => "Police, probation, prison or youth offending team – no custodial sentence", + }, + "7" => { + "value" => "Voluntary agency", + }, + "17" => { + "value" => "Children’s Social Care", + }, + "16" => { + "value" => "Other", + }, + }.freeze + else + { + "1" => { + "value" => "Internal transfer", + "hint" => "Where the tenant has moved to another social property owned by the same landlord.", + }, + "2" => { + "value" => "Tenant applied directly (no referral or nomination)", + }, + "3" => { + "value" => "Nominated by a local housing authority", + }, + "4" => { + "value" => "Referred by local authority housing department", + }, + "8" => { + "value" => "Re-located through official housing mobility scheme", + }, + "10" => { + "value" => "Other social landlord", + }, + "9" => { + "value" => "Community learning disability team", + }, + "14" => { + "value" => "Community mental health team", + }, + "15" => { + "value" => "Health service", + }, + "12" => { + "value" => "Police, probation or prison", + }, + "7" => { + "value" => "Voluntary agency", + }, + "13" => { + "value" => "Youth offending team", + }, + "17" => { + "value" => "Children’s Social Care", + }, + "16" => { + "value" => "Other", + }, + }.freeze + end + end + + QUESTION_NUMBER_FROM_YEAR = { 2023 => 85, 2024 => 84 }.freeze +end diff --git a/app/models/form/lettings/questions/referral_hsc.rb b/app/models/form/lettings/questions/referral_hsc.rb new file mode 100644 index 000000000..a5b9c32f0 --- /dev/null +++ b/app/models/form/lettings/questions/referral_hsc.rb @@ -0,0 +1,32 @@ +class Form::Lettings::Questions::ReferralHsc < ::Form::Question + def initialize(id, hsh, page) + super + @id = "referral" + @copy_key = "lettings.household_situation.referral.hsc" + @type = "radio" + @check_answers_card_number = 0 + @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + end + + def answer_options + { + "15" => { + "value" => "Health service", + }, + "9" => { + "value" => "Community learning disability team", + }, + "14" => { + "value" => "Community mental health team", + }, + "24" => { + "value" => "Adult social services", + }, + "17" => { + "value" => "Children's social care", + }, + }.freeze + end + + QUESTION_NUMBER_FROM_YEAR = { 2025 => 84 }.freeze +end diff --git a/app/models/form/lettings/questions/referral_justice.rb b/app/models/form/lettings/questions/referral_justice.rb new file mode 100644 index 000000000..0e02e0c42 --- /dev/null +++ b/app/models/form/lettings/questions/referral_justice.rb @@ -0,0 +1,23 @@ +class Form::Lettings::Questions::ReferralJustice < ::Form::Question + def initialize(id, hsh, page) + super + @id = "referral" + @copy_key = "lettings.household_situation.referral.justice" + @type = "radio" + @check_answers_card_number = 0 + @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + end + + def answer_options + { + "18" => { + "value" => "With a custodial sentence", + }, + "19" => { + "value" => "No custodial sentence", + }, + }.freeze + end + + QUESTION_NUMBER_FROM_YEAR = { 2025 => 84 }.freeze +end diff --git a/app/models/form/lettings/questions/referral_la.rb b/app/models/form/lettings/questions/referral_la.rb new file mode 100644 index 000000000..7a654df88 --- /dev/null +++ b/app/models/form/lettings/questions/referral_la.rb @@ -0,0 +1,29 @@ +class Form::Lettings::Questions::ReferralLa < ::Form::Question + def initialize(id, hsh, page) + super + @id = "referral" + @copy_key = "lettings.household_situation.referral.la" + @type = "radio" + @check_answers_card_number = 0 + @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + end + + def answer_options + { + "21" => { + "value" => "Local authority lettings", + }, + "3" => { + "value" => "PRP lettings nominated by a local authority", + }, + "4" => { + "value" => "PRP support lettings referred by a local authority", + }, + "22" => { + "value" => "Other", + }, + }.freeze + end + + QUESTION_NUMBER_FROM_YEAR = { 2025 => 84 }.freeze +end diff --git a/app/models/form/lettings/questions/referral_prp.rb b/app/models/form/lettings/questions/referral_prp.rb index 96da2cba3..44799bb8c 100644 --- a/app/models/form/lettings/questions/referral_prp.rb +++ b/app/models/form/lettings/questions/referral_prp.rb @@ -2,104 +2,25 @@ class Form::Lettings::Questions::ReferralPrp < ::Form::Question def initialize(id, hsh, page) super @id = "referral" - @copy_key = "lettings.household_situation.referral.general_needs.prp" + @copy_key = "lettings.household_situation.referral.prp" @type = "radio" @check_answers_card_number = 0 @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] end def answer_options - if form.start_year_2024_or_later? - { - "1" => { - "value" => "Internal transfer", - "hint" => "Where the tenant has moved to another social property owned by the same landlord.", - }, - "2" => { - "value" => "Tenant applied directly (no referral or nomination)", - }, - "3" => { - "value" => "Nominated by a local housing authority", - }, - "8" => { - "value" => "Re-located through official housing mobility scheme", - }, - "10" => { - "value" => "Other social landlord", - }, - "9" => { - "value" => "Community learning disability team", - }, - "14" => { - "value" => "Community mental health team", - }, - "15" => { - "value" => "Health service", - }, - "18" => { - "value" => "Police, probation, prison or youth offending team – tenant had custodial sentence", - }, - "19" => { - "value" => "Police, probation, prison or youth offending team – no custodial sentence", - }, - "7" => { - "value" => "Voluntary agency", - }, - "17" => { - "value" => "Children’s Social Care", - }, - "16" => { - "value" => "Other", - }, - }.freeze - else - { - "1" => { - "value" => "Internal transfer", - "hint" => "Where the tenant has moved to another social property owned by the same landlord.", - }, - "2" => { - "value" => "Tenant applied directly (no referral or nomination)", - }, - "3" => { - "value" => "Nominated by a local housing authority", - }, - "4" => { - "value" => "Referred by local authority housing department", - }, - "8" => { - "value" => "Re-located through official housing mobility scheme", - }, - "10" => { - "value" => "Other social landlord", - }, - "9" => { - "value" => "Community learning disability team", - }, - "14" => { - "value" => "Community mental health team", - }, - "15" => { - "value" => "Health service", - }, - "12" => { - "value" => "Police, probation or prison", - }, - "7" => { - "value" => "Voluntary agency", - }, - "13" => { - "value" => "Youth offending team", - }, - "17" => { - "value" => "Children’s Social Care", - }, - "16" => { - "value" => "Other", - }, - }.freeze - end + { + "1" => { + "value" => "Internal transfer from another property with the same landlord", + }, + "10" => { + "value" => "A different PRP landlord", + }, + "23" => { + "value" => "Other", + }, + }.freeze end - QUESTION_NUMBER_FROM_YEAR = { 2023 => 85, 2024 => 84 }.freeze + QUESTION_NUMBER_FROM_YEAR = { 2025 => 84 }.freeze end diff --git a/app/models/form/lettings/questions/referral_type.rb b/app/models/form/lettings/questions/referral_type.rb new file mode 100644 index 000000000..5ff0f411e --- /dev/null +++ b/app/models/form/lettings/questions/referral_type.rb @@ -0,0 +1,38 @@ +class Form::Lettings::Questions::ReferralType < ::Form::Question + def initialize(id, hsh, page) + super + @id = "referral_type" + @copy_key = "lettings.household_situation.referral.type" + @type = "radio" + @check_answers_card_number = 0 + @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + end + + def answer_options + { + "1" => { + "value" => "Direct", + }, + "2" => { + "value" => "From a local authority housing register or waiting list", + }, + "3" => { + "value" => "From a PRP-only housing register or waiting list (no local authority involvement)", + }, + "4" => { + "value" => "Health and social care services", + }, + "5" => { + "value" => "Police, probation, prison or youth offending team", + }, + "6" => { + "value" => "Voluntary agency", + }, + "7" => { + "value" => "Other", + }, + }.freeze + end + + QUESTION_NUMBER_FROM_YEAR = { 2025 => 84 }.freeze +end diff --git a/app/models/form/lettings/subsections/household_situation.rb b/app/models/form/lettings/subsections/household_situation.rb index dc3fd608b..8bf747f01 100644 --- a/app/models/form/lettings/subsections/household_situation.rb +++ b/app/models/form/lettings/subsections/household_situation.rb @@ -21,11 +21,28 @@ class Form::Lettings::Subsections::HouseholdSituation < ::Form::Subsection Form::Lettings::Pages::ReasonablePreference.new("reasonable_preference", nil, self), Form::Lettings::Pages::ReasonablePreferenceReason.new(nil, nil, self), Form::Lettings::Pages::AllocationSystem.new("allocation_system", nil, self), - Form::Lettings::Pages::Referral.new(nil, nil, self), - Form::Lettings::Pages::ReferralPrp.new(nil, nil, self), - Form::Lettings::Pages::ReferralSupportedHousing.new(nil, nil, self), - Form::Lettings::Pages::ReferralSupportedHousingPrp.new(nil, nil, self), + referral_questions, Form::Lettings::Pages::ReferralValueCheck.new(nil, nil, self), - ].compact + ].flatten.compact + end + + def referral_questions + if form.start_year_2025_or_later? + [ + Form::Lettings::Pages::ReferralType.new(nil, nil, self), + Form::Lettings::Pages::ReferralDirect.new(nil, nil, self), + Form::Lettings::Pages::ReferralLa.new(nil, nil, self), + Form::Lettings::Pages::ReferralPrp.new(nil, nil, self), + Form::Lettings::Pages::ReferralHsc.new(nil, nil, self), + Form::Lettings::Pages::ReferralJustice.new(nil, nil, self), + ] + else + [ + Form::Lettings::Pages::ReferralGeneralNeeds.new(nil, nil, self), + Form::Lettings::Pages::ReferralGeneralNeedsPrp.new(nil, nil, self), + Form::Lettings::Pages::ReferralSupportedHousing.new(nil, nil, self), + Form::Lettings::Pages::ReferralSupportedHousingPrp.new(nil, nil, self), + ] + end end end diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index 63da6d628..723ab30b6 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -32,6 +32,7 @@ module Validations::HouseholdValidations if record.is_reason_permanently_decanted? && record.referral.present? && !record.is_internal_transfer? record.errors.add :referral, I18n.t("validations.lettings.household.referral.leaving_last_settled_home.reason_permanently_decanted") + record.errors.add :referral_type, I18n.t("validations.lettings.household.referral.leaving_last_settled_home.reason_permanently_decanted") record.errors.add :reason, I18n.t("validations.lettings.household.reason.leaving_last_settled_home.not_internal_transfer") end @@ -171,6 +172,7 @@ module Validations::HouseholdValidations label = record.form.get_question("prevten", record).present? ? record.form.get_question("prevten", record).label_from_value(record.prevten) : "" record.errors.add :prevten, :internal_transfer_non_social_housing, message: I18n.t("validations.lettings.household.prevten.internal_transfer", prevten: label) record.errors.add :referral, :internal_transfer_non_social_housing, message: I18n.t("validations.lettings.household.referral.prevten_invalid", prevten: label) + record.errors.add :referral_type, :internal_transfer_non_social_housing, message: I18n.t("validations.lettings.household.referral.prevten_invalid", prevten: label) end end @@ -180,6 +182,7 @@ module Validations::HouseholdValidations if record.is_internal_transfer? && record.owning_organisation.provider_type == "PRP" && record.is_prevten_la_general_needs? record.errors.add :prevten, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.lettings.household.prevten.la_general_needs.internal_transfer") record.errors.add :referral, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.lettings.household.referral.la_general_needs.internal_transfer") + record.errors.add :referral_type, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.lettings.household.referral.la_general_needs.internal_transfer") end end diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index 1cf710857..364cfe732 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -11,6 +11,7 @@ module Validations::PropertyValidations if record.is_relet_to_temp_tenant? && REFERRAL_INVALID_TMP.include?(record.referral) record.errors.add :rsnvac, I18n.t("validations.lettings.property.rsnvac.referral_invalid") record.errors.add :referral, :referral_invalid, message: I18n.t("validations.lettings.property.referral.rsnvac_non_temp") + record.errors.add :referral_type, :referral_invalid, message: I18n.t("validations.lettings.property.referral.rsnvac_non_temp") end if record.renewal.present? && record.renewal.zero? && record.rsnvac == 14 diff --git a/app/services/bulk_upload/lettings/year2024/row_parser.rb b/app/services/bulk_upload/lettings/year2024/row_parser.rb index 461469200..20eb4dccd 100644 --- a/app/services/bulk_upload/lettings/year2024/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2024/row_parser.rb @@ -418,6 +418,7 @@ class BulkUpload::Lettings::Year2024::RowParser validate :validate_no_and_dont_know_disabled_needs_conjunction, on: :after_log validate :validate_no_housing_needs_questions_answered, on: :after_log validate :validate_reasonable_preference_homeless, on: :after_log + validate :validate_reasonable_preference_dont_know, on: :after_log validate :validate_condition_effects, on: :after_log validate :validate_if_log_already_exists, on: :after_log, if: -> { FeatureToggle.bulk_upload_duplicate_log_check_enabled? } @@ -751,6 +752,15 @@ private end end + def validate_reasonable_preference_dont_know + if rp_dontknow_conflict? + errors.add(:field_111, I18n.t("#{ERROR_BASE_KEY}.reasonpref.conflict.dont_know")) + %i[field_107 field_108 field_109 field_110].each do |field| + errors.add(field, I18n.t("#{ERROR_BASE_KEY}.reasonpref.conflict.other")) if send(field) == 1 + end + end + end + def validate_reasonable_preference_homeless reason_fields = %i[field_107 field_108 field_109 field_110 field_111] if field_106 == 1 && reason_fields.all? { |field| attributes[field.to_s].blank? } @@ -1270,11 +1280,11 @@ private attributes["ppostcode_full"] = ppostcode_full attributes["reasonpref"] = field_106 - attributes["rp_homeless"] = field_107 - attributes["rp_insan_unsat"] = field_108 - attributes["rp_medwel"] = field_109 - attributes["rp_hardship"] = field_110 - attributes["rp_dontknow"] = field_111 + attributes["rp_homeless"] = field_107 unless rp_dontknow_conflict? + attributes["rp_insan_unsat"] = field_108 unless rp_dontknow_conflict? + attributes["rp_medwel"] = field_109 unless rp_dontknow_conflict? + attributes["rp_hardship"] = field_110 unless rp_dontknow_conflict? + attributes["rp_dontknow"] = field_111 unless rp_dontknow_conflict? attributes["cbl"] = cbl attributes["chr"] = chr @@ -1662,4 +1672,15 @@ private def bulk_upload_organisation Organisation.find(bulk_upload.organisation_id) end + + def rp_dontknow_conflict? + other_reason_fields = %i[field_107 field_108 field_109 field_110] + if field_106 == 1 + selected_reasons = other_reason_fields.select { |field| send(field) == 1 } + dont_know_selected = field_111 == 1 + + return true if selected_reasons.any? && dont_know_selected + end + false + end end diff --git a/app/services/bulk_upload/lettings/year2025/row_parser.rb b/app/services/bulk_upload/lettings/year2025/row_parser.rb index 9332fbabd..1f4a80f9b 100644 --- a/app/services/bulk_upload/lettings/year2025/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2025/row_parser.rb @@ -417,6 +417,7 @@ class BulkUpload::Lettings::Year2025::RowParser validate :validate_no_and_dont_know_disabled_needs_conjunction, on: :after_log validate :validate_no_housing_needs_questions_answered, on: :after_log validate :validate_reasonable_preference_homeless, on: :after_log + validate :validate_reasonable_preference_dont_know, on: :after_log validate :validate_condition_effects, on: :after_log validate :validate_if_log_already_exists, on: :after_log, if: -> { FeatureToggle.bulk_upload_duplicate_log_check_enabled? } @@ -750,6 +751,15 @@ private end end + def validate_reasonable_preference_dont_know + if rp_dontknow_conflict? + errors.add(:field_111, I18n.t("#{ERROR_BASE_KEY}.reasonpref.conflict.dont_know")) + %i[field_107 field_108 field_109 field_110].each do |field| + errors.add(field, I18n.t("#{ERROR_BASE_KEY}.reasonpref.conflict.other")) if send(field) == 1 + end + end + end + def validate_reasonable_preference_homeless reason_fields = %i[field_107 field_108 field_109 field_110 field_111] if field_106 == 1 && reason_fields.all? { |field| attributes[field.to_s].blank? } @@ -1094,6 +1104,7 @@ private accessible_register: %i[field_115], letting_allocation: %i[field_112 field_113 field_114 field_115], + referral_type: %i[field_116], referral: %i[field_116], net_income_known: %i[field_117], @@ -1267,11 +1278,11 @@ private attributes["ppostcode_full"] = ppostcode_full attributes["reasonpref"] = field_106 - attributes["rp_homeless"] = field_107 - attributes["rp_insan_unsat"] = field_108 - attributes["rp_medwel"] = field_109 - attributes["rp_hardship"] = field_110 - attributes["rp_dontknow"] = field_111 + attributes["rp_homeless"] = field_107 unless rp_dontknow_conflict? + attributes["rp_insan_unsat"] = field_108 unless rp_dontknow_conflict? + attributes["rp_medwel"] = field_109 unless rp_dontknow_conflict? + attributes["rp_hardship"] = field_110 unless rp_dontknow_conflict? + attributes["rp_dontknow"] = field_111 unless rp_dontknow_conflict? attributes["cbl"] = cbl attributes["chr"] = chr @@ -1279,6 +1290,7 @@ private attributes["accessible_register"] = accessible_register attributes["letting_allocation_unknown"] = letting_allocation_unknown + attributes["referral_type"] = referral_type attributes["referral"] = field_116 attributes["net_income_known"] = net_income_known @@ -1664,4 +1676,33 @@ private "R" # refused end end + + def rp_dontknow_conflict? + other_reason_fields = %i[field_107 field_108 field_109 field_110] + if field_106 == 1 + selected_reasons = other_reason_fields.select { |field| send(field) == 1 } + dont_know_selected = field_111 == 1 + + return true if selected_reasons.any? && dont_know_selected + end + false + end + + def referral_type + mapping = { + 1 => [20, 2, 8], + 2 => [21, 3, 4, 22], + 3 => [1, 10, 23], + 4 => [15, 9, 14, 24, 17], + 5 => [18, 19], + 6 => [7], + 7 => [16], + } + + mapping.each do |key, values| + return key if values.include?(field_116) + end + + 0 + end end diff --git a/config/locales/forms/2025/lettings/household_situation.en.yml b/config/locales/forms/2025/lettings/household_situation.en.yml index fbbdcf657..22c7052eb 100644 --- a/config/locales/forms/2025/lettings/household_situation.en.yml +++ b/config/locales/forms/2025/lettings/household_situation.en.yml @@ -112,29 +112,39 @@ en: question_text: "How was this letting allocated?" referral: - supported_housing: - prp: - page_header: "" - check_answer_label: "Source of referral for letting" - check_answer_prompt: "" - hint_text: "" - question_text: "What was the source of referral for this letting?" - la: - page_header: "" - check_answer_label: "Source of referral for letting" - check_answer_prompt: "" - hint_text: "You told us that you are a local authority. We have removed some options because of this." - question_text: "What was the source of referral for this letting?" - general_needs: - prp: - page_header: "" - check_answer_label: "Source of referral for letting" - check_answer_prompt: "" - hint_text: "You told us that the needs type is general needs. We have removed some options because of this." - question_text: "What was the source of referral for this letting?" - la: - page_header: "" - check_answer_label: "Source of referral for letting" - check_answer_prompt: "" - hint_text: "You told us that you are a local authority and that the needs type is general needs. We have removed some options because of this." - question_text: "What was the source of referral for this letting?" + type: + page_header: "" + check_answer_label: "Source of referral for letting" + check_answer_prompt: "Select source of referral" + hint_text: "" + question_text: "What was the source of referral for this letting?" + direct: + page_header: "" + check_answer_label: "Source of referral for letting" + check_answer_prompt: "Select source of referral" + hint_text: "" + question_text: "What was the source of referral for this letting?" + la: + page_header: "" + check_answer_label: "Source of referral for letting" + check_answer_prompt: "Select source of referral" + hint_text: "" + question_text: "What was the source of referral for this letting?" + prp: + page_header: "" + check_answer_label: "Source of referral for letting" + check_answer_prompt: "Select source of referral" + hint_text: "" + question_text: "What was the source of referral for this letting?" + hsc: + page_header: "" + check_answer_label: "Source of referral for letting" + check_answer_prompt: "Select source of referral" + hint_text: "" + question_text: "What was the source of referral for this letting?" + justice: + page_header: "" + check_answer_label: "Source of referral for letting" + check_answer_prompt: "Select source of referral" + hint_text: "" + question_text: "What was the source of referral for this letting?" diff --git a/config/locales/validations/lettings/2024/bulk_upload.en.yml b/config/locales/validations/lettings/2024/bulk_upload.en.yml index 18d051b4d..7431b074a 100644 --- a/config/locales/validations/lettings/2024/bulk_upload.en.yml +++ b/config/locales/validations/lettings/2024/bulk_upload.en.yml @@ -58,3 +58,7 @@ en: invalid: "Select a valid nationality." charges: missing_charges: "Please enter the %{sentence_fragment}. If there is no %{sentence_fragment}, please enter '0'." + reasonpref: + conflict: + dont_know: "You cannot select 'Don't know' if any of the other reasonable preference reasons are also selected." + other: "You cannot select this reasonable preference reason as you've also selected 'Don't know' as a reason." diff --git a/config/locales/validations/lettings/2025/bulk_upload.en.yml b/config/locales/validations/lettings/2025/bulk_upload.en.yml index 7acb0726c..28866de21 100644 --- a/config/locales/validations/lettings/2025/bulk_upload.en.yml +++ b/config/locales/validations/lettings/2025/bulk_upload.en.yml @@ -58,3 +58,7 @@ en: invalid: "Select a valid nationality." charges: missing_charges: "Please enter the %{sentence_fragment}. If there is no %{sentence_fragment}, please enter '0'." + reasonpref: + conflict: + dont_know: "You cannot select 'Don't know' if any of the other reasonable preference reasons are also selected." + other: "You cannot select this reasonable preference reason as you've also selected 'Don't know' as a reason." diff --git a/db/migrate/20250225180643_add_referral_type_to_lettings_logs.rb b/db/migrate/20250225180643_add_referral_type_to_lettings_logs.rb new file mode 100644 index 000000000..4df8fe9dc --- /dev/null +++ b/db/migrate/20250225180643_add_referral_type_to_lettings_logs.rb @@ -0,0 +1,5 @@ +class AddReferralTypeToLettingsLogs < ActiveRecord::Migration[7.2] + def change + add_column :lettings_logs, :referral_type, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index f041f506e..82d67b432 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: 2025_02_19_122817) do +ActiveRecord::Schema[7.2].define(version: 2025_02_25_180643) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -373,6 +373,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_02_19_122817) do t.integer "partner_under_16_value_check" t.integer "multiple_partners_value_check" t.bigint "created_by_id" + t.integer "referral_type" t.boolean "manual_address_entry_selected", default: false 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" diff --git a/lib/tasks/recalculate_invalid_reasonpref_dontknow.rake b/lib/tasks/recalculate_invalid_reasonpref_dontknow.rake new file mode 100644 index 000000000..14d387662 --- /dev/null +++ b/lib/tasks/recalculate_invalid_reasonpref_dontknow.rake @@ -0,0 +1,12 @@ +desc "Bulk update logs with invalid rp_dontknow values" +task recalculate_invalid_rpdontknow: :environment do + validation_trigger_condition = "rp_dontknow = 1 AND (rp_homeless = 1 OR rp_insan_unsat = 1 OR rp_medwel = 1 OR rp_hardship = 1)" + + LettingsLog.filter_by_year(2024).where(validation_trigger_condition).find_each do |log| + log.rp_dontknow = 0 + + unless log.save + Rails.logger.info "Could not save changes to lettings log #{log.id}" + end + end +end diff --git a/spec/factories/lettings_log.rb b/spec/factories/lettings_log.rb index 1581527d0..ad81bca5d 100644 --- a/spec/factories/lettings_log.rb +++ b/spec/factories/lettings_log.rb @@ -160,6 +160,7 @@ FactoryBot.define do is_carehome { 0 } declaration { 1 } first_time_property_let_as_social_housing { 0 } + referral_type { 1 } referral { 2 } uprn_known { 0 } joint { 3 } diff --git a/spec/lib/tasks/recalculate_invalid_reasonpref_dontknow_spec.rb b/spec/lib/tasks/recalculate_invalid_reasonpref_dontknow_spec.rb new file mode 100644 index 000000000..3487f3989 --- /dev/null +++ b/spec/lib/tasks/recalculate_invalid_reasonpref_dontknow_spec.rb @@ -0,0 +1,70 @@ +require "rails_helper" +require "rake" + +RSpec.describe "recalculate_invalid_reasonpref_dontknow" do + subject(:task) { Rake::Task["recalculate_invalid_rpdontknow"] } + + before do + Rake.application.rake_require("tasks/recalculate_invalid_reasonpref_dontknow") + Rake::Task.define_task(:environment) + task.reenable + end + + let(:invalid_logs) { create_list(:lettings_log, 5, :completed, reasonpref: 1, rp_dontknow: 1, rp_homeless: 1, rp_insan_unsat: rand(2), rp_medwel: rand(2), rp_hardship: rand(2), updated_at: Time.zone.local(2024, 4, 2, 12, 0, 0)) } + let(:pre_2024_invalid_logs) do + create_list(:lettings_log, 5, :completed, reasonpref: 1, rp_dontknow: 1, rp_homeless: 1, rp_insan_unsat: rand(2), rp_medwel: rand(2), rp_hardship: rand(2)).each do |log| + log.startdate = Time.zone.local(rand(2021..2023), 4, 1) + log.save!(validate: false) + end + end + let(:valid_logs) { create_list(:lettings_log, 3, :completed, reasonpref: 1, rp_dontknow: 0, rp_homeless: 1, rp_insan_unsat: 1, rp_medwel: rand(2), rp_hardship: rand(2), updated_at: Time.zone.local(2024, 4, 2, 12, 0, 0)) } + + it "updates the logs from 2024/25 with invalid rp_dontknow values" do + invalid_logs.each do |log| + expect(log.reasonpref).to eq(1) + expect(log.rp_dontknow).to eq(1) + expect(log.rp_homeless).to eq(1) + end + task.invoke + invalid_logs.each do |log| + log.reload + expect(log.reasonpref).to eq(1) + expect(log.rp_dontknow).to eq(0) + expect(log.rp_homeless).to eq(1) + expect(log.updated_at).not_to eq(Time.zone.local(2024, 4, 2, 12, 0, 0)) + end + end + + it "does not update the logs pre 2024 with invalid rp_dontknow values" do + pre_2024_invalid_logs.each do |log| + expect(log.reasonpref).to eq(1) + expect(log.rp_dontknow).to eq(1) + expect(log.rp_homeless).to eq(1) + end + task.invoke + pre_2024_invalid_logs.each do |log| + log.reload + expect(log.reasonpref).to eq(1) + expect(log.rp_dontknow).to eq(1) + expect(log.rp_homeless).to eq(1) + end + end + + it "does not update the logs with valid rp_dontknow values" do + valid_logs.each do |log| + expect(log.reasonpref).to eq(1) + expect(log.rp_dontknow).to eq(0) + expect(log.rp_homeless).to eq(1) + expect(log.rp_insan_unsat).to eq(1) + end + task.invoke + valid_logs.each do |log| + log.reload + expect(log.reasonpref).to eq(1) + expect(log.rp_dontknow).to eq(0) + expect(log.rp_homeless).to eq(1) + expect(log.rp_insan_unsat).to eq(1) + expect(log.updated_at).to eq(Time.zone.local(2024, 4, 2, 12, 0, 0)) + end + end +end diff --git a/spec/models/form/lettings/questions/referral_prp_spec.rb b/spec/models/form/lettings/questions/referral_general_needs_prp_spec.rb similarity index 97% rename from spec/models/form/lettings/questions/referral_prp_spec.rb rename to spec/models/form/lettings/questions/referral_general_needs_prp_spec.rb index a10b6d383..832394bcc 100644 --- a/spec/models/form/lettings/questions/referral_prp_spec.rb +++ b/spec/models/form/lettings/questions/referral_general_needs_prp_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe Form::Lettings::Questions::ReferralPrp, type: :model do +RSpec.describe Form::Lettings::Questions::ReferralGeneralNeedsPrp, type: :model do subject(:question) { described_class.new(question_id, question_definition, page) } let(:question_id) { nil } diff --git a/spec/models/form/lettings/questions/referral_spec.rb b/spec/models/form/lettings/questions/referral_general_needs_spec.rb similarity index 97% rename from spec/models/form/lettings/questions/referral_spec.rb rename to spec/models/form/lettings/questions/referral_general_needs_spec.rb index 75e6c2f42..2f7c7a864 100644 --- a/spec/models/form/lettings/questions/referral_spec.rb +++ b/spec/models/form/lettings/questions/referral_general_needs_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe Form::Lettings::Questions::Referral, type: :model do +RSpec.describe Form::Lettings::Questions::ReferralGeneralNeeds, type: :model do subject(:question) { described_class.new(question_id, question_definition, page) } let(:question_id) { nil } diff --git a/spec/models/form/lettings/subsections/household_situation_spec.rb b/spec/models/form/lettings/subsections/household_situation_spec.rb index d672b3ccc..eb056ca7a 100644 --- a/spec/models/form/lettings/subsections/household_situation_spec.rb +++ b/spec/models/form/lettings/subsections/household_situation_spec.rb @@ -19,6 +19,7 @@ RSpec.describe Form::Lettings::Subsections::HouseholdSituation, type: :model do context "with form year before 2024" do before do allow(form).to receive(:start_year_2024_or_later?).and_return(false) + allow(form).to receive(:start_year_2025_or_later?).and_return(false) end it "has correct pages" do @@ -46,9 +47,10 @@ RSpec.describe Form::Lettings::Subsections::HouseholdSituation, type: :model do end end - context "with form year >= 2024" do + context "with form year is 2024" do before do allow(form).to receive(:start_year_2024_or_later?).and_return(true) + allow(form).to receive(:start_year_2025_or_later?).and_return(false) end it "has correct pages" do @@ -77,6 +79,40 @@ RSpec.describe Form::Lettings::Subsections::HouseholdSituation, type: :model do end end + context "with form year is 2025" do + before do + allow(form).to receive(:start_year_2024_or_later?).and_return(true) + allow(form).to receive(:start_year_2025_or_later?).and_return(true) + end + + it "has correct pages" do + expect(household_situation.pages.map(&:id)).to eq( + %w[ + time_lived_in_local_authority + time_on_waiting_list + reason_for_leaving_last_settled_home + reason_for_leaving_last_settled_home_renewal + reasonother_value_check + previous_housing_situation + previous_housing_situation_renewal + homelessness + previous_postcode + previous_local_authority + reasonable_preference + reasonable_preference_reason + allocation_system + referral_type + referral_direct + referral_la + referral_prp + referral_hsc + referral_justice + referral_value_check + ], + ) + end + end + it "has the correct id" do expect(household_situation.id).to eq("household_situation") end diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index b6af03736..2086e55f1 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -129,33 +129,42 @@ RSpec.describe Validations::HouseholdValidations do 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_type = 1 record.referral = 2 household_validator.validate_reason_for_leaving_last_settled_home(record) expect(record.errors["reason"]) .to include(match(I18n.t("validations.lettings.household.reason.leaving_last_settled_home.not_internal_transfer"))) expect(record.errors["referral"]) .to include(match(I18n.t("validations.lettings.household.referral.leaving_last_settled_home.reason_permanently_decanted"))) + expect(record.errors["referral_type"]) + .to include(match(I18n.t("validations.lettings.household.referral.leaving_last_settled_home.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_type = 3 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 + expect(record.errors["referral_type"]) + .to be_empty end it "cannot have a PRP as landlord and Housing situation before this letting cannot be LA general needs" do record.owning_organisation.provider_type = "PRP" record.prevten = 30 + record.referral_type = 3 record.referral = 1 household_validator.validate_referral(record) expect(record.errors["referral"]) .to include(match(I18n.t("validations.lettings.household.referral.la_general_needs.internal_transfer"))) + expect(record.errors["referral_type"]) + .to include(match(I18n.t("validations.lettings.household.referral.la_general_needs.internal_transfer"))) expect(record.errors["prevten"]) .to include(match(I18n.t("validations.lettings.household.prevten.la_general_needs.internal_transfer"))) @@ -163,6 +172,8 @@ RSpec.describe Validations::HouseholdValidations do household_validator.validate_referral(record) expect(record.errors["referral"]) .to include(match(I18n.t("validations.lettings.household.referral.la_general_needs.internal_transfer"))) + expect(record.errors["referral_type"]) + .to include(match(I18n.t("validations.lettings.household.referral.la_general_needs.internal_transfer"))) expect(record.errors["prevten"]) .to include(match(I18n.t("validations.lettings.household.prevten.la_general_needs.internal_transfer"))) end @@ -603,37 +614,45 @@ RSpec.describe Validations::HouseholdValidations do context "when homelessness is assessed" do it "can be internal transfer" do record.homeless = 11 + record.referral_type = 3 record.referral = 1 household_validator.validate_referral(record) expect(record.errors["referral"]).to be_empty + expect(record.errors["referral_type"]).to be_empty expect(record.errors["homeless"]).to be_empty end it "can be non internal transfer" do record.owning_organisation.provider_type = "PRP" record.homeless = 0 + record.referral_type = 2 record.referral = 3 household_validator.validate_referral(record) expect(record.errors["referral"]).to be_empty + expect(record.errors["referral_type"]).to be_empty expect(record.errors["homeless"]).to be_empty end end context "when homelessness is other" do it "cannot be internal transfer" do + record.referral_type = 3 record.referral = 1 record.homeless = 7 household_validator.validate_referral(record) expect(record.errors["referral"]).to be_empty + expect(record.errors["referral_type"]).to be_empty expect(record.errors["homeless"]).to be_empty end it "can be non internal transfer" do record.owning_organisation.provider_type = "PRP" + record.referral_type = 2 record.referral = 3 record.homeless = 1 household_validator.validate_referral(record) expect(record.errors["referral"]).to be_empty + expect(record.errors["referral_type"]).to be_empty expect(record.errors["homeless"]).to be_empty end end @@ -715,6 +734,7 @@ RSpec.describe Validations::HouseholdValidations do context "when the referral is internal transfer" do it "prevten can be 9" do + record.referral_type = 3 record.referral = 1 record.prevten = 9 household_validator.validate_previous_housing_situation(record) @@ -722,6 +742,8 @@ RSpec.describe Validations::HouseholdValidations do .to be_empty expect(record.errors["referral"]) .to be_empty + expect(record.errors["referral_type"]) + .to be_empty end [ @@ -740,6 +762,7 @@ RSpec.describe Validations::HouseholdValidations do { code: 29, label: "Prison or approved probation hostel" }, ].each do |prevten| it "prevten cannot be #{prevten[:code]}" do + record.referral_type = 3 record.referral = 1 record.prevten = prevten[:code] household_validator.validate_previous_housing_situation(record) @@ -748,6 +771,8 @@ RSpec.describe Validations::HouseholdValidations do .to include(match I18n.t("validations.lettings.household.prevten.internal_transfer", prevten: label)) expect(record.errors["referral"]) .to include(match I18n.t("validations.lettings.household.referral.prevten_invalid", prevten: "")) + expect(record.errors["referral_type"]) + .to include(match I18n.t("validations.lettings.household.referral.prevten_invalid", prevten: "")) end end end diff --git a/spec/models/validations/property_validations_spec.rb b/spec/models/validations/property_validations_spec.rb index 142cb2491..88939959b 100644 --- a/spec/models/validations/property_validations_spec.rb +++ b/spec/models/validations/property_validations_spec.rb @@ -168,6 +168,7 @@ RSpec.describe Validations::PropertyValidations do it "expects that the letting source can be a referral" do log.prevten = 0 + log.referral_type = 1 log.referral = 2 property_validator.validate_rsnvac(log) expect(log.errors["rsnvac"]).to be_empty diff --git a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb index a3392e50d..e4b34ac36 100644 --- a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb @@ -1247,7 +1247,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end end - context "when some reasonable preference options are seleceted" do + context "when some reasonable preference options are selected" do let(:attributes) { setup_section_params.merge({ bulk_upload:, field_106: "1", field_107: "1", field_108: nil, field_109: "1", field_110: nil, field_111: nil }) } it "sets the rest of the options to 0" do @@ -1260,7 +1260,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end end - context "when some reasonable preference options are seleceted but reasonpref is No" do + context "when some reasonable preference options are selected but reasonpref is No" do let(:attributes) { setup_section_params.merge({ bulk_upload:, field_106: "2", field_107: "1", field_108: nil, field_109: "1", field_110: nil, field_111: nil }) } it "sets the options to nil" do @@ -1285,6 +1285,20 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do expect(parser.errors[:field_111]).to be_present end end + + context "when reasonpref is Yes, some reasonable preferences are selected but also so is 'Don't know'" do + let(:attributes) { setup_section_params.merge({ bulk_upload:, field_106: "1", field_107: "1", field_108: "1", field_109: nil, field_110: nil, field_111: "1" }) } + + it "is not permitted" do + parser.valid? + expect(parser.errors[:field_107]).to be_present + expect(parser.errors[:field_108]).to be_present + expect(parser.errors[:field_111]).to be_present + expect(parser.errors[:field_107]).to include(I18n.t("validations.lettings.2024.bulk_upload.reasonpref.conflict.other")) + expect(parser.errors[:field_108]).to include(I18n.t("validations.lettings.2024.bulk_upload.reasonpref.conflict.other")) + expect(parser.errors[:field_111]).to include(I18n.t("validations.lettings.2024.bulk_upload.reasonpref.conflict.dont_know")) + end + end end describe "#field_116" do # referral diff --git a/spec/services/bulk_upload/lettings/year2025/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2025/row_parser_spec.rb index a822d6f2a..3f0ef35b9 100644 --- a/spec/services/bulk_upload/lettings/year2025/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2025/row_parser_spec.rb @@ -1096,6 +1096,19 @@ RSpec.describe BulkUpload::Lettings::Year2025::RowParser do expect(parser.errors[:field_111]).to be_present end end + + context "when some reasonable preference options are selected" do + let(:attributes) { setup_section_params.merge({ bulk_upload:, field_106: "1", field_107: "1", field_108: nil, field_109: "1", field_110: nil, field_111: nil }) } + + it "sets the rest of the options to 0" do + parser.valid? + expect(parser.log.rp_homeless).to eq(1) + expect(parser.log.rp_insan_unsat).to eq(0) + expect(parser.log.rp_medwel).to eq(1) + expect(parser.log.rp_hardship).to eq(0) + expect(parser.log.rp_dontknow).to eq(0) + end + end end describe "#field_116" do # referral