Browse Source

Move validate property postcode from shared to property validations

pull/2744/head
Manny Dinssa 8 months ago
parent
commit
53f757b601
  1. 8
      app/models/validations/property_validations.rb
  2. 8
      app/models/validations/sales/property_validations.rb
  3. 8
      app/models/validations/shared_validations.rb
  4. 6
      config/locales/validations/lettings/property_information.en.yml
  5. 1
      config/locales/validations/sales/property_information.en.yml

8
app/models/validations/property_validations.rb

@ -57,4 +57,12 @@ module Validations::PropertyValidations
record.errors.add :uprn, I18n.t("validations.property.uprn.invalid") record.errors.add :uprn, I18n.t("validations.property.uprn.invalid")
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.lettings.property_information.postcode_full.invalid")
record.errors.add :postcode_full, :wrong_format, message: error_message
end
end
end end

8
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") record.errors.add :uprn, I18n.t("validations.sales.property_information.uprn.invalid")
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.sales.property_information.postcode_full.invalid")
record.errors.add :postcode_full, :wrong_format, message: error_message
end
end
end end

8
app/models/validations/shared_validations.rb

@ -66,14 +66,6 @@ module Validations::SharedValidations
end end
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) def inactive_status(date, resource)
return if date.blank? || resource.blank? return if date.blank? || resource.blank?

6
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."

1
config/locales/validations/sales/property_information.en.yml

@ -6,6 +6,7 @@ en:
postcode_must_match_previous: postcode_must_match_previous:
joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match." joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match."
not_joint_purchase: "Buyer’s 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: ppostcode_full:
postcode_must_match_previous: postcode_must_match_previous:
joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match." joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match."

Loading…
Cancel
Save