Browse Source

Update non staircasing mortgage validation (#2238)

pull/2239/head
kosiakkatrina 10 months ago committed by GitHub
parent
commit
f266099e19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 18
      app/models/validations/sales/sale_information_validations.rb
  2. 4
      config/locales/en.yml
  3. 50
      spec/models/validations/sales/sale_information_validations_spec.rb

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

@ -100,13 +100,23 @@ module Validations::Sales::SaleInformationValidations
end end
def validate_non_staircasing_mortgage(record) def validate_non_staircasing_mortgage(record)
return unless record.mortgage && record.value && record.deposit && record.equity return unless record.value && record.deposit && record.equity
return unless record.is_not_staircasing? return unless record.is_not_staircasing?
return unless record.saledate && record.form.start_year_after_2024? return unless record.saledate && record.form.start_year_after_2024?
if record.mortgage_and_deposit_total != record.expected_shared_ownership_deposit_value if record.mortgage_used?
%i[mortgage value deposit equity].each do |field| return unless record.mortgage
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"))
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_used", 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
elsif record.mortgage_not_used?
if record.deposit != record.expected_shared_ownership_deposit_value
%i[mortgageused value deposit equity].each do |field|
record.errors.add field, I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_not_used", deposit: record.field_formatted_as_currency("deposit"), expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value"))
end
end end
end end
end end

4
config/locales/en.yml

@ -622,7 +622,9 @@ 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." non_staircasing_mortgage:
mortgage_used: "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."
mortgage_not_used: "The deposit is %{deposit} and the purchase price times by the equity is %{expected_shared_ownership_deposit_value}. As no mortgage was used, these figures should be the same."
stairowned: stairowned:
mortgageused_dont_know: "The percentage owned has to be 100% if the mortgage used is 'Don’t know'" mortgageused_dont_know: "The percentage owned has to be 100% if the mortgage used is 'Don’t know'"
merge_request: merge_request:

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

@ -686,7 +686,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
describe "#validate_non_staircasing_mortgage" do 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) } let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, deposit: 5_000, value: 30_000, equity: 28, ownershipsch: 1, type: 30, saledate: now) }
around do |example| around do |example|
Timecop.freeze(now) do Timecop.freeze(now) do
@ -741,6 +741,54 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
expect(record.errors["equity"]).to be_empty expect(record.errors["equity"]).to be_empty
end end
end end
context "when mortgage is not used" do
before do
record.mortgageused = 2
end
context "when 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["mortgageused"]).to include("The deposit is £5,000.00 and the purchase price times by the equity is £8,400.00. As no mortgage was used, these figures should be the same.")
expect(record.errors["value"]).to include("The deposit is £5,000.00 and the purchase price times by the equity is £8,400.00. As no mortgage was used, these figures should be the same.")
expect(record.errors["deposit"]).to include("The deposit is £5,000.00 and the purchase price times by the equity is £8,400.00. As no mortgage was used, these figures should be the same.")
expect(record.errors["equity"]).to include("The deposit is £5,000.00 and the purchase price times by the equity is £8,400.00. As no mortgage was used, 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["mortgageused"]).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 DEPOSIT equals VALUE * EQUITY/100" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 2, deposit: 15_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["mortgageused"]).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
context "when it is a 2023 log" do context "when it is a 2023 log" do

Loading…
Cancel
Save