From 2209bfec705caed022399a3e5cb383100f96471b Mon Sep 17 00:00:00 2001 From: oscar-richardson-softwire Date: Fri, 16 Jan 2026 16:54:42 +0000 Subject: [PATCH] Ask address and UPRN questions for 2026 and later logs --- app/models/derived_variables/lettings_log_variables.rb | 5 ++++- app/models/form/lettings/pages/address_fallback.rb | 2 +- app/models/form/lettings/pages/address_search.rb | 2 +- app/models/lettings_log.rb | 8 ++++++-- app/models/validations/property_validations.rb | 10 ++++++++++ .../validations/lettings/property_information.en.yml | 2 ++ 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index 9ea820dc0..69daeb820 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -170,7 +170,10 @@ module DerivedVariables::LettingsLogVariables self.referral = 7 if referral_type == 6 self.referral = 16 if referral_type == 7 - reset_address_fields! if is_supported_housing? + if location_changed? + reset_address_fields! + self.la = nil + end set_checkbox_values! end diff --git a/app/models/form/lettings/pages/address_fallback.rb b/app/models/form/lettings/pages/address_fallback.rb index f7503e3af..8129bf821 100644 --- a/app/models/form/lettings/pages/address_fallback.rb +++ b/app/models/form/lettings/pages/address_fallback.rb @@ -3,7 +3,7 @@ class Form::Lettings::Pages::AddressFallback < ::Form::Page super @id = "address" @copy_key = "lettings.property_information.address" - @depends_on = [{ "is_supported_housing?" => false, "manual_address_entry_selected" => true }] + @depends_on = [{ "is_address_asked?" => true, "manual_address_entry_selected" => true }] @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] end diff --git a/app/models/form/lettings/pages/address_search.rb b/app/models/form/lettings/pages/address_search.rb index 866018d45..59cc40d80 100644 --- a/app/models/form/lettings/pages/address_search.rb +++ b/app/models/form/lettings/pages/address_search.rb @@ -3,7 +3,7 @@ class Form::Lettings::Pages::AddressSearch < ::Form::Page super @id = "address_search" @copy_key = "sales.property_information.address_search" - @depends_on = [{ "is_supported_housing?" => false, "manual_address_entry_selected" => false }] + @depends_on = [{ "is_address_asked?" => true, "manual_address_entry_selected" => false }] @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] end diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 9c9894d32..5e84f06dc 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -184,7 +184,7 @@ class LettingsLog < Log end def la - if location + if (!form.start_year_2026_or_later? && location) || (form.start_year_2026_or_later? && !super) location.linked_local_authorities.active(form.start_date).first&.code || location.location_code else super @@ -192,7 +192,7 @@ class LettingsLog < Log end def postcode_full - if location + if (!form.start_year_2026_or_later? && location) || (form.start_year_2026_or_later? && !super) location.postcode else super @@ -773,6 +773,10 @@ class LettingsLog < Log rsnvac != 15 && rsnvac_was == 15 end + def is_address_asked? + form.start_year_2026_or_later? || !is_supported_housing? + end + private def reset_invalid_unresolved_log_fields! diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index c5ed9728a..d18ec9b44 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -50,6 +50,16 @@ module Validations::PropertyValidations error_message = I18n.t("validations.lettings.property.postcode_full.invalid") record.errors.add :postcode_full, :wrong_format, message: error_message end + + return unless record.form.start_year_2026_or_later? + + location_postcode = record.location&.postcode + return unless location_postcode + + if postcode != location_postcode + record.errors.add :uprn, I18n.t("validations.lettings.property.uprn.postcode_does_not_match_scheme_location_postcode") + record.errors.add :postcode_full, I18n.t("validations.lettings.property.postcode_full.does_not_match_scheme_location_postcode") + end end # see also: this validation in sales/property_validations.rb diff --git a/config/locales/validations/lettings/property_information.en.yml b/config/locales/validations/lettings/property_information.en.yml index 8f706c261..9eec4b2f7 100644 --- a/config/locales/validations/lettings/property_information.en.yml +++ b/config/locales/validations/lettings/property_information.en.yml @@ -6,6 +6,7 @@ en: invalid: "Enter a postcode in the correct format, for example AA1 1AA." not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for lettings in England." la_not_valid_for_date: "%{la} does not exist on the tenancy start date, due to a change in local authority names and boundaries. Please enter the local authority name in use on the tenancy start date" + does_not_match_scheme_location_postcode: "The postcode in the address does not match the postcode for the location in the scheme. Please review your answers to the address or UPRN question (whichever you answered) and the location question." rsnvac: non_temp_accommodation: "Answer cannot be re-let to tenant who occupied the same property as temporary accommodation as this accommodation is not temporary." referral_invalid: "Answer cannot be re-let to tenant who occupied the same property as temporary accommodation as a different source of referral for this letting." @@ -24,6 +25,7 @@ en: invalid: "UPRN must be 12 digits or less." not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England." la_not_valid_for_date: "%{la} does not exist on the tenancy start date, due to a change in local authority names and boundaries. Please enter the local authority name in use on the tenancy start date" + postcode_does_not_match_scheme_location_postcode: "The postcode in the address does not match the postcode for the location in the scheme. Please review your answers to the address or UPRN question (whichever you answered) and the location question." uprn_confirmation: # legacy question not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England." uprn_selection: