@ -74,17 +74,18 @@ module Validations::PropertyValidations
return unless record . la
return if record . la . in? ( LocalAuthority . england . pluck ( :code ) )
if record . is_general_needs?
record . errors . add :la , I18n . t ( " validations.lettings.property.la.not_in_england " )
record . errors . add :postcode_full , I18n . t ( " validations.lettings.property.postcode_full.not_in_england " )
record . errors . add :uprn , I18n . t ( " validations.lettings.property.uprn.not_in_england " )
record . errors . add :uprn_selection , I18n . t ( " validations.lettings.property.uprn_selection.not_in_england " )
if record . is_general_needs?
if record . uprn . present?
record . errors . add :startdate , I18n . t ( " validations.lettings.property.startdate.address_not_in_england " )
else
record . errors . add :startdate , I18n . t ( " validations.lettings.property.startdate.postcode_not_in_england " )
end
elsif record . is_supported_housing? && ! record . read_attribute ( :la ) # `!record.read_attribute(:la)` being satisfied means the address questions (including LA) haven't been answered and the LA is coming from location.
elsif record . is_supported_housing?
record . errors . add :location_id , I18n . t ( " validations.lettings.property.location_id.not_in_england " )
record . errors . add :scheme_id , I18n . t ( " validations.lettings.property.scheme_id.not_in_england " )
record . errors . add :startdate , I18n . t ( " validations.lettings.property.startdate.location_not_in_england " )
@ -103,16 +104,15 @@ module Validations::PropertyValidations
# only compare end date if it exists
return if record . startdate > = la . start_date && ( la . end_date . nil? || record . startdate < = la . end_date )
if record . is_general_needs?
record . errors . add :la , I18n . t ( " validations.lettings.property.la.la_not_valid_for_date " , la : la . name )
record . errors . add :postcode_full , I18n . t ( " validations.lettings.property.postcode_full.la_not_valid_for_date " , la : la . name )
record . errors . add :uprn , I18n . t ( " validations.lettings.property.uprn.la_not_valid_for_date " , la : la . name )
record . errors . add :uprn_selection , I18n . t ( " validations.lettings.property.uprn_selection.la_not_valid_for_date " , la : la . name )
record . errors . add :startdate , I18n . t ( " validations.lettings.property.startdate.la_not_valid_for_date " , la : la . name )
elsif record . is_supported_housing? && ! record . read_attribute ( :la ) # `!record.read_attribute(:la)` being satisfied means the address questions (including LA) haven't been answered and the LA is coming from location.
if record . is_supported_housing?
record . errors . add :location_id , I18n . t ( " validations.lettings.property.location_id.la_not_valid_for_date " , la : la . name )
record . errors . add :scheme_id , I18n . t ( " validations.lettings.property.scheme_id.la_not_valid_for_date " , la : la . name )
record . errors . add :startdate , I18n . t ( " validations.lettings.property.startdate.la_not_valid_for_date " , la : la . name )
end
end
end