From a89446b66629a25aaf22a2655cb2e748aadb731b Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:05:10 +0000 Subject: [PATCH] Prevent changing logs to 2025 with invalid addresses --- app/models/validations/property_validations.rb | 2 +- .../validations/sales/property_validations.rb | 3 ++- .../validations/sales/property_information.en.yml | 14 +++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index 1cf710857..e13de5272 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -50,7 +50,7 @@ module Validations::PropertyValidations end def validate_la_in_england(record) - return unless record.form.start_year_2025_or_later? + return unless record.form.start_year_2025_or_later? || (record.startdate_changed? && record.startdate_was.year == 2025 && record.startdate.year == 2024) if record.is_general_needs? return unless record.la diff --git a/app/models/validations/sales/property_validations.rb b/app/models/validations/sales/property_validations.rb index 7fd4d2440..48d659f36 100644 --- a/app/models/validations/sales/property_validations.rb +++ b/app/models/validations/sales/property_validations.rb @@ -40,7 +40,8 @@ module Validations::Sales::PropertyValidations end def validate_la_in_england(record) - return unless record.form.start_year_2025_or_later? && record.la.present? + return unless record.form.start_year_2025_or_later? || (record.startdate_changed? && record.startdate_was.year == 2025 && record.startdate.year == 2024) + return unless record.la return if record.la.in?(LocalAuthority.england.pluck(:code)) record.errors.add :la, I18n.t("validations.sales.property_information.la.not_in_england") diff --git a/config/locales/validations/sales/property_information.en.yml b/config/locales/validations/sales/property_information.en.yml index 9014f1d78..3ac00a2c0 100644 --- a/config/locales/validations/sales/property_information.en.yml +++ b/config/locales/validations/sales/property_information.en.yml @@ -7,7 +7,7 @@ en: joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match." not_joint_purchase: "Buyer’s last accommodation and discounted ownership postcodes must match." invalid: "Enter a postcode in the correct format, for example AA1 1AA." - not_in_england: "It looks like you have entered a postcode outside of England - only submit Lettings forms for Lettings that occur in England" + not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for sales in England." ppostcode_full: postcode_must_match_previous: joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match." @@ -21,7 +21,7 @@ en: joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match." not_joint_purchase: "Buyer’s last accommodation and discounted ownership postcodes must match." invalid: "UPRN must be 12 digits or less." - not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for lettings in England." + not_in_england: "It looks like you have entered an address outside of England. Only create logs for sales in England." beds: bedsits_have_max_one_bedroom: "Number of bedrooms must be 1 if the property is a bedsit." proptype: @@ -29,11 +29,11 @@ en: uprn_known: invalid: "You must answer UPRN known?" la: - not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England." + not_in_england: "It looks like you have entered an address outside of England. Only create logs for sales in England." uprn_confirmation: - not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England." + not_in_england: "It looks like you have entered an address outside of England. Only create logs for sales in England." uprn_selection: - not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England." + not_in_england: "It looks like you have entered an address outside of England. Only create logs for sales in England." saledate: - postcode_not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for lettings in England." - address_not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England." + postcode_not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for sales in England." + address_not_in_england: "It looks like you have entered an address outside of England. Only create logs for sales in England."