Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
1.2 KiB

module Validations::LocalAuthorityValidations
POSTCODE_REGEXP = Validations::PropertyValidations::POSTCODE_REGEXP
def validate_previous_accommodation_postcode(record)
postcode = record.ppostcode_full
if record.previous_postcode_known? && (postcode.blank? || !postcode.match(POSTCODE_REGEXP))
error_message = I18n.t("validations.postcode")
record.errors.add :ppostcode_full, error_message
end
end
3 years ago
def validate_la(record)
if record.la_known? && record.la.blank?
record.errors.add :la, I18n.t("validations.property.la.la_known")
end
if record.owning_organisation && record.owning_organisation.local_authorities.present? &&
3 years ago
record.la && !record.owning_organisation.local_authorities.include?(record.la)
la_name = record.form.get_question("la", record).label_from_value(record.la)
org_name = record.owning_organisation.name
postcode = UKPostcode.parse(record.postcode_full) if record.postcode_full
3 years ago
record.errors.add :la, I18n.t("validations.property.la.la_invalid_for_org", org_name:, la_name:)
record.errors.add :postcode_known, I18n.t("validations.property.la.postcode_invalid_for_org", org_name:, postcode:)
3 years ago
end
end
end