Browse Source

refactor: dry out validation

pull/1404/head
Sam Seed 3 years ago
parent
commit
69fae70991
  1. 12
      app/models/validations/sales/financial_validations.rb
  2. 2
      config/locales/en.yml

12
app/models/validations/sales/financial_validations.rb

@ -55,10 +55,14 @@ module Validations::Sales::FinancialValidations
def validate_percentage_bought_at_least_threshold(record)
return unless record.stairbought && record.type
if ([2, 18, 16, 24].include? record.type) && record.stairbought < 10
record.errors.add :stairbought, I18n.t("validations.financial.staircasing.percentage_bought_must_be_at_least_threshold", percentage: 10)
elsif record.type == 30 && record.stairbought < 1
record.errors.add :stairbought, I18n.t("validations.financial.staircasing.percentage_bought_must_be_at_least_threshold", percentage: 1)
if [2, 18, 16, 24].include? record.type
threshold = 10
elsif record.type == 30
threshold = 1
end
if threshold && record.stairbought < threshold
record.errors.add :stairbought, I18n.t("validations.financial.staircasing.percentage_bought_must_be_at_least_threshold", threshold:)
end
end

2
config/locales/en.yml

@ -302,7 +302,7 @@ en:
staircasing:
percentage_bought_must_be_greater_than_percentage_owned: "Total percentage buyer now owns must be more than percentage bought in this transaction"
older_person_percentage_owned_maximum_75: "Percentage cannot be above 75% under Older Person's Shared Ownership"
percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{percentage}%"
percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{threshold}%"
household:
reasonpref:

Loading…
Cancel
Save