Module: Validations::Sales::HouseholdValidations
- Includes:
- Validations::SharedValidations
- Defined in:
- sales/household_validations.rb
Instance Method Summary collapse
- #validate_buyer1_previous_tenure(record) ⇒ Object
- #validate_buyer_not_child(record) ⇒ Object
- #validate_buyers_living_in_property(record) ⇒ Object
- #validate_child_12_years_younger(record) ⇒ Object
- #validate_partner_count(record) ⇒ Object
- #validate_person_age_and_relationship_matches_economic_status(record) ⇒ Object
- #validate_person_age_matches_economic_status(record) ⇒ Object
- #validate_person_age_matches_relationship(record) ⇒ Object
Instance Method Details
#validate_buyer1_previous_tenure(record) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'sales/household_validations.rb', line 18 def validate_buyer1_previous_tenure(record) return unless record.saledate && record.form.start_year_after_2024? return unless record.discounted_ownership_sale? && record.prevten if [3, 4, 5, 6, 7, 9, 0].include?(record.prevten) record.errors.add :prevten, I18n.t("validations.household.prevten.invalid_for_discounted_sale") record.errors.add :ownershipsch, I18n.t("validations.household.prevten.invalid_for_discounted_sale") end end |
#validate_buyer_not_child(record) ⇒ Object
108 109 110 111 112 113 |
# File 'sales/household_validations.rb', line 108 def validate_buyer_not_child(record) return unless record.saledate && record.form.start_year_after_2024? record.errors.add "ecstat1", I18n.t("validations.household.ecstat.buyer_cannot_be_child", buyer_index: "1") if person_is_economic_child?(record.ecstat1) record.errors.add "ecstat2", I18n.t("validations.household.ecstat.buyer_cannot_be_child", buyer_index: "2") if person_is_economic_child?(record.ecstat2) && record.joint_purchase? end |
#validate_buyers_living_in_property(record) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'sales/household_validations.rb', line 8 def validate_buyers_living_in_property(record) return unless record.form.start_date.year >= 2023 if record.buyers_will_live_in? && record.buyer_one_will_not_live_in_property? && record.buyer_two_will_not_live_in_property? record.errors.add :buylivein, I18n.t("validations.household.buylivein.buyers_will_live_in_property_values_inconsistent_setup") record.errors.add :buy1livein, I18n.t("validations.household.buylivein.buyers_will_live_in_property_values_inconsistent") record.errors.add :buy2livein, I18n.t("validations.household.buylivein.buyers_will_live_in_property_values_inconsistent") end end |
#validate_child_12_years_younger(record) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'sales/household_validations.rb', line 91 def validate_child_12_years_younger(record) return unless record.saledate && !record.form.start_year_after_2024? (2..6).each do |person_num| buyer_1_age = record.public_send("age1") person_age = record.public_send("age#{person_num}") relationship = record.public_send("relat#{person_num}") next unless buyer_1_age && person_age && relationship next unless 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.age.child_12_years_younger") end end |
#validate_partner_count(record) ⇒ Object
4 5 6 |
# File 'sales/household_validations.rb', line 4 def validate_partner_count(record) shared_validate_partner_count(record, 6) end |
#validate_person_age_and_relationship_matches_economic_status(record) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'sales/household_validations.rb', line 46 def validate_person_age_and_relationship_matches_economic_status(record) return unless record.saledate && !record.form.start_year_after_2024? (2..6).each do |person_num| age = record.public_send("age#{person_num}") economic_status = record.public_send("ecstat#{person_num}") relationship = record.public_send("relat#{person_num}") next unless age && economic_status && relationship age_between_16_19 = age.between?(16, 19) student = person_is_fulltime_student?(economic_status) economic_status_refused = person_economic_status_refused?(economic_status) child = person_is_child?(relationship) if age_between_16_19 && !(student || economic_status_refused) && child record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.must_be_student") record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.cannot_be_16_19.child_not_student") record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.cannot_be_child.16_19_not_student") end next unless !age_between_16_19 && student && child record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.must_be_16_19") record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.cannot_be_student.child_not_16_19") record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.cannot_be_child.student_not_16_19") end end |
#validate_person_age_matches_economic_status(record) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'sales/household_validations.rb', line 74 def validate_person_age_matches_economic_status(record) (2..6).each do |person_num| age = record.public_send("age#{person_num}") economic_status = record.public_send("ecstat#{person_num}") next unless age && economic_status if age < 16 && !economic_status_is_child_other_or_refused?(economic_status) && !record.form.start_year_after_2024? record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:) record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16_ecstat", person_num:) end if person_is_economic_child?(economic_status) && age > 16 record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_over_16", person_num:) record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_over_16", person_num:) end end end |
#validate_person_age_matches_relationship(record) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'sales/household_validations.rb', line 28 def validate_person_age_matches_relationship(record) return unless record.saledate && !record.form.start_year_after_2024? (2..6).each do |person_num| age = record.public_send("age#{person_num}") relationship = record.public_send("relat#{person_num}") next unless age && relationship if age < 16 && !relationship_is_child_other_or_refused?(relationship) record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16_relat_sales", person_num:) record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_under_16_sales", person_num:) elsif age >= 20 && person_is_child?(relationship) record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_over_20") record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_over_20") end end end |