From 53f757b601cdcb7ea64a952d12de50c84133bc5f Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Mon, 4 Nov 2024 15:20:53 +0000 Subject: [PATCH] Move validate property postcode from shared to property validations --- app/models/validations/property_validations.rb | 8 ++++++++ app/models/validations/sales/property_validations.rb | 8 ++++++++ app/models/validations/shared_validations.rb | 8 -------- .../validations/lettings/property_information.en.yml | 6 ++++++ .../locales/validations/sales/property_information.en.yml | 7 ++++--- 5 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 config/locales/validations/lettings/property_information.en.yml diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index 52afecb49..fd878d846 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -57,4 +57,12 @@ module Validations::PropertyValidations record.errors.add :uprn, I18n.t("validations.property.uprn.invalid") end + + def validate_property_postcode(record) + postcode = record.postcode_full + if record.postcode_known? && (postcode.blank? || !postcode.match(POSTCODE_REGEXP)) + error_message = I18n.t("validations.lettings.property_information.postcode_full.invalid") + record.errors.add :postcode_full, :wrong_format, message: error_message + end + end end diff --git a/app/models/validations/sales/property_validations.rb b/app/models/validations/sales/property_validations.rb index 59d616c9a..55a57815a 100644 --- a/app/models/validations/sales/property_validations.rb +++ b/app/models/validations/sales/property_validations.rb @@ -28,4 +28,12 @@ module Validations::Sales::PropertyValidations record.errors.add :uprn, I18n.t("validations.sales.property_information.uprn.invalid") end + + def validate_property_postcode(record) + postcode = record.postcode_full + if record.postcode_known? && (postcode.blank? || !postcode.match(POSTCODE_REGEXP)) + error_message = I18n.t("validations.sales.property_information.postcode_full.invalid") + record.errors.add :postcode_full, :wrong_format, message: error_message + end + end end diff --git a/app/models/validations/shared_validations.rb b/app/models/validations/shared_validations.rb index f509e0cf1..7d824941d 100644 --- a/app/models/validations/shared_validations.rb +++ b/app/models/validations/shared_validations.rb @@ -66,14 +66,6 @@ module Validations::SharedValidations end end - def validate_property_postcode(record) - postcode = record.postcode_full - if record.postcode_known? && (postcode.blank? || !postcode.match(POSTCODE_REGEXP)) - error_message = I18n.t("validations.shared.postcode") - record.errors.add :postcode_full, :wrong_format, message: error_message - end - end - def inactive_status(date, resource) return if date.blank? || resource.blank? diff --git a/config/locales/validations/lettings/property_information.en.yml b/config/locales/validations/lettings/property_information.en.yml new file mode 100644 index 000000000..ed42acb4c --- /dev/null +++ b/config/locales/validations/lettings/property_information.en.yml @@ -0,0 +1,6 @@ +en: + validations: + lettings: + property_information: + postcode_full: + invalid: "Enter a postcode in the correct format, for example AA1 1AA." diff --git a/config/locales/validations/sales/property_information.en.yml b/config/locales/validations/sales/property_information.en.yml index e69f90edf..a91e47849 100644 --- a/config/locales/validations/sales/property_information.en.yml +++ b/config/locales/validations/sales/property_information.en.yml @@ -3,11 +3,12 @@ en: sales: property_information: postcode_full: - postcode_must_match_previous: + postcode_must_match_previous: 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." ppostcode_full: - postcode_must_match_previous: + postcode_must_match_previous: joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match." not_joint_purchase: "Buyer’s last accommodation and discounted ownership postcodes must match." ownershipsch: @@ -15,7 +16,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." uprn: - postcode_must_match_previous: + postcode_must_match_previous: 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."