From bd210f77a7ab98696a6aed90cea4d9f2faeee0df Mon Sep 17 00:00:00 2001 From: Samuel Young Date: Mon, 2 Feb 2026 10:04:02 +0000 Subject: [PATCH] CLDC-4190: Invalidate all referral fields if any are wrong --- .../lettings/year2026/row_parser.rb | 68 ++++++++++++++++++- .../lettings/2026/bulk_upload.en.yml | 1 + 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/app/services/bulk_upload/lettings/year2026/row_parser.rb b/app/services/bulk_upload/lettings/year2026/row_parser.rb index 61ab00152..97da93d47 100644 --- a/app/services/bulk_upload/lettings/year2026/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2026/row_parser.rb @@ -426,6 +426,7 @@ class BulkUpload::Lettings::Year2026::RowParser 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? } + validate :validate_referral_fields, on: :after_log validate :validate_owning_org_data_given, on: :after_log validate :validate_owning_org_exists, on: :after_log @@ -995,6 +996,56 @@ private end end + def field_116_valid? + if owning_organisation&.la? + [1, 2, 3, 4].include?(field_116) + else + field_116.blank? + end + end + + def field_130_valid? + if owning_organisation&.prp? + [5, 6, 7, 8, 9].include?(field_130) + else + field_130.blank? + end + end + + def field_131_valid? + case field_130 + when 6 + [1, 2, 3, 4].include?(field_131) + when 7 + [5, 6, 7, 8].include?(field_131) + else + field_131.blank? + end + end + + def field_132_valid? + case field_131 + when 1 + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].include?(field_132) + when 7 + [11, 12, 13, 14, 15, 16, 17, 18, 19, 20].include?(field_132) + else + field_132.blank? + end + end + + def referral_fields_valid? + field_116_valid? && field_130_valid? && field_131_valid? && field_132_valid? + end + + def validate_referral_fields + return if referral_fields_valid? + + %i[field_116 field_130 field_131 field_132].each do |field| + errors.add(field, I18n.t("#{ERROR_BASE_KEY}.referral.invalid_option")) + end + end + def field_mapping_for_errors { lettype: [:field_11], @@ -1694,6 +1745,11 @@ private def referral_register return unless owning_organisation + # by default CORE will ingest all these fields and nil questions that aren't asked + # here, we specifically want the log to be invalid if any of the referral fields are wrong + # BU will only consider a log invalid if its incomplete + # so, nil these fields if any are invalid + return unless referral_fields_valid? if owning_organisation.la? field_116 @@ -1703,12 +1759,20 @@ private end def referral_noms - field_131 + return unless owning_organisation + return unless referral_fields_valid? + + if owning_organisation.prp? + field_131 + end end def referral_org return unless owning_organisation + return unless referral_fields_valid? - field_132 + if owning_organisation.prp? + field_132 + end end end diff --git a/config/locales/validations/lettings/2026/bulk_upload.en.yml b/config/locales/validations/lettings/2026/bulk_upload.en.yml index 8ac7fc378..b8257c8fb 100644 --- a/config/locales/validations/lettings/2026/bulk_upload.en.yml +++ b/config/locales/validations/lettings/2026/bulk_upload.en.yml @@ -42,6 +42,7 @@ en: referral: general_needs_prp_referred_by_la: "The source of the referral cannot be referred by local authority housing department for a general needs log." nominated_by_local_ha_but_la: "The source of the referral cannot be Nominated by local housing authority as your organisation is a local authority." + invalid_option: "Your answers for each part of \"What is the source of referral for this letting?\" are incompatible with each other. Use the bulk upload specification or paper form to see which combinations are valid (available from ‘Collection resources’ on the homepage)." scheme: must_relate_to_org: "This scheme code does not belong to the owning organisation or managing organisation." location: