Browse Source

Validate non staircasing mortgage value (#2223)

pull/2226/head
kosiakkatrina 11 months ago committed by GitHub
parent
commit
46aae6e774
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      app/models/sales_log.rb
  2. 12
      app/models/validations/sales/sale_information_validations.rb
  3. 1
      config/locales/en.yml
  4. 73
      spec/models/validations/sales/sale_information_validations_spec.rb

4
app/models/sales_log.rb

@ -491,4 +491,8 @@ class SalesLog < Log
value * discount / 100 value * discount / 100
end end
def is_not_staircasing?
staircase == 2 || staircase == 3
end
end end

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

@ -98,4 +98,16 @@ module Validations::Sales::SaleInformationValidations
end end
end end
end end
def validate_non_staircasing_mortgage(record)
return unless record.mortgage && record.value && record.deposit && record.equity
return unless record.is_not_staircasing?
return unless record.saledate && record.form.start_year_after_2024?
if record.mortgage_and_deposit_total != record.expected_shared_ownership_deposit_value
%i[mortgage value deposit equity].each do |field|
record.errors.add field, I18n.t("validations.sale_information.non_staircasing_mortgage", mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value"))
end
end
end
end end

1
config/locales/en.yml

@ -622,6 +622,7 @@ en:
value: value:
over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £136,400 for properties in London." over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £136,400 for properties in London."
over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £102,400 for properties outside of London." over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £102,400 for properties outside of London."
non_staircasing_mortgage: "The mortgage and deposit added together is %{mortgage_and_deposit_total} and the purchase price times by the equity is %{expected_shared_ownership_deposit_value}. These figures should be the same."
merge_request: merge_request:
organisation_part_of_another_merge: "This organisation is part of another merge - select a different one" organisation_part_of_another_merge: "This organisation is part of another merge - select a different one"
organisation_not_selected: "Select an organisation from the search list" organisation_not_selected: "Select an organisation from the search list"

73
spec/models/validations/sales/sale_information_validations_spec.rb

@ -596,7 +596,6 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
end end
end end
context "when the collection year is before 2024" do context "when the collection year is before 2024" do
let(:record) { build(:sales_log, ownershipsch: 1, type: 24, saledate: now, stairbought: 90) } let(:record) { build(:sales_log, ownershipsch: 1, type: 24, saledate: now, stairbought: 90) }
let(:now) { Time.zone.local(2023, 4, 4) } let(:now) { Time.zone.local(2023, 4, 4) }
@ -685,4 +684,76 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
end end
end end
describe "#validate_non_staircasing_mortgage" do
let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, deposit: 5_000, value: 30_000, equity: 28, ownershipsch: 1, type: 30, saledate: now) }
around do |example|
Timecop.freeze(now) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
context "with a log in the 24/25 collection year" do
let(:now) { Time.zone.local(2024, 4, 4) }
context "when MORTGAGE + DEPOSIT does not equal VALUE * EQUITY/100 " do
context "and it is not a staircase transaction" do
before do
record.staircase = 2
end
it "adds an error" do
sale_information_validator.validate_non_staircasing_mortgage(record)
expect(record.errors["mortgage"]).to include("The mortgage and deposit added together is £15,000.00 and the purchase price times by the equity is £8,400.00. These figures should be the same.")
expect(record.errors["value"]).to include("The mortgage and deposit added together is £15,000.00 and the purchase price times by the equity is £8,400.00. These figures should be the same.")
expect(record.errors["deposit"]).to include("The mortgage and deposit added together is £15,000.00 and the purchase price times by the equity is £8,400.00. These figures should be the same.")
expect(record.errors["equity"]).to include("The mortgage and deposit added together is £15,000.00 and the purchase price times by the equity is £8,400.00. These figures should be the same.")
end
end
context "and it is a staircase transaction" do
before do
record.staircase = 1
end
it "does not add an error" do
sale_information_validator.validate_non_staircasing_mortgage(record)
expect(record.errors["mortgage"]).to be_empty
expect(record.errors["value"]).to be_empty
expect(record.errors["deposit"]).to be_empty
expect(record.errors["equity"]).to be_empty
end
end
end
context "when MORTGAGE + DEPOSIT equals VALUE * EQUITY/100" do
let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, staircase: 2, deposit: 5_000, value: 30_000, equity: 50, ownershipsch: 1, type: 30, saledate: now) }
it "does not add an error" do
sale_information_validator.validate_non_staircasing_mortgage(record)
expect(record.errors["mortgage"]).to be_empty
expect(record.errors["value"]).to be_empty
expect(record.errors["deposit"]).to be_empty
expect(record.errors["equity"]).to be_empty
end
end
end
context "when it is a 2023 log" do
let(:now) { Time.zone.local(2023, 4, 1) }
let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, staircase: 2, deposit: 5_000, value: 30_000, equity: 28, ownershipsch: 1, type: 30, saledate: now) }
it "does not add an error" do
sale_information_validator.validate_non_staircasing_mortgage(record)
expect(record.errors["mortgage"]).to be_empty
expect(record.errors["value"]).to be_empty
expect(record.errors["deposit"]).to be_empty
expect(record.errors["equity"]).to be_empty
end
end
end
end end

Loading…
Cancel
Save