Browse Source

feat: add validation behaviour

pull/1400/head
natdeanlewissoftwire 3 years ago
parent
commit
ce95351d8e
  1. 43
      app/models/validations/sales/financial_validations.rb
  2. 3
      config/locales/en.yml

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

@ -70,6 +70,27 @@ module Validations::Sales::FinancialValidations
end end
end end
def validate_equity_in_range_for_year_and_type(record)
return unless record.type && record.equity && record.collection_start_year
if record.collection_start_year == 2022
ranges = EQUITY_RANGES_FOR_TYPES_BY_COLLECTION_START_YEAR[2022]
elsif record.collection_start_year >= 2023
ranges = EQUITY_RANGES_FOR_TYPES_BY_COLLECTION_START_YEAR[2023]
end
if ranges.key?(record.type)
range = ranges[record.type]
if record.equity < range["min"]
record.errors.add :type, I18n.t("validations.financial.equity.under_min", min_equity: range["min"])
record.errors.add :equity, I18n.t("validations.financial.equity.under_min", min_equity: range["min"])
elsif record.equity > range["max"]
record.errors.add :type, I18n.t("validations.financial.equity.over_max")
record.errors.add :equity, I18n.t("validations.financial.equity.over_max")
end
end
end
private private
def is_relationship_child?(relationship) def is_relationship_child?(relationship)
@ -79,4 +100,26 @@ private
def is_economic_status_child?(economic_status) def is_economic_status_child?(economic_status)
economic_status == 9 economic_status == 9
end end
EQUITY_RANGES_FOR_TYPES_BY_COLLECTION_START_YEAR = {
2022 => {
2 => { "min" => 25, "max" => 75 },
30 => { "min" => 10, "max" => 75 },
18 => { "min" => 25, "max" => 75 },
16 => { "min" => 10, "max" => 75 },
24 => { "min" => 25, "max" => 75 },
# 28 => ranges don't apply
31 => { "min" => 0, "max" => 75 },
},
2023 => {
2 => { "min" => 10, "max" => 75 },
30 => { "min" => 25, "max" => 75 },
18 => { "min" => 25, "max" => 75 },
16 => { "min" => 10, "max" => 75 },
24 => { "min" => 25, "max" => 75 },
# 28 => ranges don't apply
31 => { "min" => 0, "max" => 75 },
32 => { "min" => 0, "max" => 75 },
},
}.freeze
end end

3
config/locales/en.yml

@ -297,6 +297,9 @@ en:
staircasing: staircasing:
percentage_bought_must_be_greater_than_percentage_owned: "Total percentage buyer now owns must be more than percentage bought in this transaction" 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" older_person_percentage_owned_maximum_75: "Percentage cannot be above 75% under Older Person's Shared Ownership"
equity:
under_min: "The minimum initial equity stake for this type of shared ownership sale is %{min_equity}%"
over_max: "The maximum initial equity stake is 75%"
household: household:
reasonpref: reasonpref:

Loading…
Cancel
Save