Browse Source

CLDC-2026 Add minimum staircasing validation for shared ownership sales (#1404)

* feat: add validation that staircase % is >= threshold

* refactor: dry out validation

* refactor: correctly order shared ownership types in array

* test: add tests for stairbought threshold validation

* chore: lint

* feat: all staircasing transactions must have stairbought >= 1%

* feat: add validation to shared ownership type as well

* chore: lint

* refactor: simplify no errors tests

* refactor: simplify tests by using iteration
pull/1430/head
SamSeed-Softwire 2 years ago committed by GitHub
parent
commit
d695c2fc64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      app/models/validations/sales/financial_validations.rb
  2. 3
      config/locales/en.yml
  3. 42
      spec/models/validations/sales/financial_validations_spec.rb

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

@ -52,6 +52,21 @@ module Validations::Sales::FinancialValidations
end
end
def validate_percentage_bought_at_least_threshold(record)
return unless record.stairbought && record.type
threshold = if [2, 16, 18, 24].include? record.type
10
else
1
end
if threshold && record.stairbought < threshold
record.errors.add :stairbought, I18n.t("validations.financial.staircasing.percentage_bought_must_be_at_least_threshold", threshold:)
record.errors.add :type, I18n.t("validations.setup.type.percentage_bought_must_be_at_least_threshold", threshold:)
end
end
def validate_child_income(record)
return unless record.income2 && record.ecstat2

3
config/locales/en.yml

@ -159,6 +159,8 @@ en:
Enter a date within the %{current_start_year_short}/%{current_end_year_short} financial year, which is between %{current_start_year_long} and %{current_end_year_long}
previous_and_current_financial_year:
"Enter a date within the %{previous_start_year_short}/%{previous_end_year_short} or %{previous_end_year_short}/%{current_end_year_short} financial years, which is between %{previous_start_year_long} and %{current_end_year_long}"
type:
percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{threshold}% for this shared ownership type"
startdate:
later_than_14_days_after: "The tenancy start date must not be later than 14 days from today’s date"
@ -302,6 +304,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 %{threshold}%"
household:
reasonpref:

42
spec/models/validations/sales/financial_validations_spec.rb

@ -160,6 +160,48 @@ RSpec.describe Validations::Sales::FinancialValidations do
end
end
describe "#validate_percentage_bought_at_least_threshold" do
let(:record) { FactoryBot.create(:sales_log) }
it "adds an error to stairbought and type if the percentage bought is less than the threshold (which is 1% by default, but higher for some shared ownership types)" do
record.stairbought = 9
[2, 16, 18, 24].each do |type|
record.type = type
financial_validator.validate_percentage_bought_at_least_threshold(record)
expect(record.errors["stairbought"]).to eq(["The minimum increase in equity while staircasing is 10%"])
expect(record.errors["type"]).to eq(["The minimum increase in equity while staircasing is 10% for this shared ownership type"])
record.errors.clear
end
record.stairbought = 0
[28, 30, 31, 32].each do |type|
record.type = type
financial_validator.validate_percentage_bought_at_least_threshold(record)
expect(record.errors["stairbought"]).to eq(["The minimum increase in equity while staircasing is 1%"])
expect(record.errors["type"]).to eq(["The minimum increase in equity while staircasing is 1% for this shared ownership type"])
record.errors.clear
end
end
it "doesn't add an error to stairbought and type if the percentage bought is less than the threshold (which is 1% by default, but higher for some shared ownership types)" do
record.stairbought = 10
[2, 16, 18, 24].each do |type|
record.type = type
financial_validator.validate_percentage_bought_at_least_threshold(record)
expect(record.errors).to be_empty
record.errors.clear
end
record.stairbought = 1
[28, 30, 31, 32].each do |type|
record.type = type
financial_validator.validate_percentage_bought_at_least_threshold(record)
expect(record.errors).to be_empty
record.errors.clear
end
end
end
describe "#validate_percentage_owned_not_too_much_if_older_person" do
let(:record) { FactoryBot.create(:sales_log) }

Loading…
Cancel
Save