Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP-4489: add different error messages for whether client has partner #5893

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions app/forms/legal_aid_applications/property_details_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class PropertyDetailsForm < BaseForm

attr_accessor(*ATTRIBUTES)

validates :property_value, presence: { unless: :draft? }
validates :property_value, allow_blank: true, currency: { greater_than_or_equal_to: 0.0 }
validate :property_value_presence
validate :property_value_amount

validates :outstanding_mortgage_amount, presence: { unless: :outstanding_mortgage_amount_presence }
validates :outstanding_mortgage_amount, allow_blank: true, currency: { greater_than_or_equal_to: 0.0 }
Expand All @@ -28,6 +28,22 @@ def attributes_to_clean

private

def property_value_presence
return if draft? || property_value.present?

errors.add(:property_value, I18n.t("activemodel.errors.models.legal_aid_application.attributes.property_value.blank#{individual}"))
end

def property_value_amount
return if property_value.blank? || property_value.to_f >= 0.0

errors.add(:property_value, I18n.t("activemodel.errors.models.legal_aid_application.attributes.property_value.greater_than_or_equal_to#{individual}"))
end

def individual
return "_with_partner" if model.applicant.has_partner_with_no_contrary_interest?
end

def outstanding_mortgage_amount_presence
draft? || model.own_home == "owned_outright"
end
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en/activemodel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ en:
blank: Select yes if your client owns a vehicle
property_value:
blank: Enter how much the home your client lives in is worth
blank_with_partner: Enter how much the home your client and their partner lives in is worth
greater_than_or_equal_to: How much the home your client lives in in must be 0 or more
greater_than_or_equal_to_with_partner: How much the home your client and their partner lives in must be 0 or more
not_a_number: How much the home your client lives in must be an amount of money, like 60,000
too_many_decimals: How much the home your client lives in cannot include more than 2 decimal numbers
outstanding_mortgage_amount:
Expand Down
Loading