Browse Source

feat: add validation

pull/1444/head
natdeanlewissoftwire 3 years ago
parent
commit
f24c32994b
  1. 14
      app/models/validations/sales/household_validations.rb
  2. 1
      config/locales/en.yml

14
app/models/validations/sales/household_validations.rb

@ -6,6 +6,7 @@ module Validations::Sales::HouseholdValidations
validate_person_age_matches_relationship(record, n)
validate_person_age_and_relationship_matches_economic_status(record, n)
validate_person_age_matches_economic_status(record, n)
validate_child_12_years_younger(record, n)
end
shared_validate_partner_count(record, 6)
end
@ -79,6 +80,19 @@ private
end
end
def validate_child_12_years_younger(record, person_num)
buyer_1_age = record.public_send("age1")
person_age = record.public_send("age#{person_num}")
relationship = record.public_send("relat#{person_num}")
return unless buyer_1_age && person_age && relationship
if person_age > buyer_1_age - 12 && person_is_child?(relationship)
record.errors.add "age1", I18n.t("validations.household.age.child_12_years_younger")
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_12_years_younger")
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_12_years_younger")
end
end
def person_is_partner?(relationship)
relationship == "P"
end

1
config/locales/en.yml

@ -341,6 +341,7 @@ en:
child_under_16: "Answer cannot be under 16 as person’s %{person_num} working situation is not ‘child under 16’"
child_over_16: "Answer cannot be over 16 as person’s %{person_num} working situation is ‘child under 16‘"
child_over_20: "Answer cannot be 20 or over as the relationship is ‘child’"
child_12_years_younger: "A child must be at least 12 years younger than their parent"
not_student_16_19: "Answer cannot be between 16 and 19 as person %{person_num} is a child of the lead tenant but is not a full-time student"
student_16_19:
cannot_be_16_19:

Loading…
Cancel
Save