diff --git a/app/models/validations/sales/financial_validations.rb b/app/models/validations/sales/financial_validations.rb index 6b36091ac..3e1d3dfb8 100644 --- a/app/models/validations/sales/financial_validations.rb +++ b/app/models/validations/sales/financial_validations.rb @@ -102,23 +102,6 @@ module Validations::Sales::FinancialValidations end end - def validate_shared_ownership_deposit(record) - return unless record.saledate && record.form.start_year_after_2024? - return unless record.mortgage || record.mortgageused == 2 || record.mortgageused == 3 - return unless record.cashdis && record.deposit && record.value && record.equity - - mortgage_value = record.mortgage || 0 - - if mortgage_value + record.deposit + record.cashdis != record.value * record.equity / 100 - %i[mortgage value deposit ownershipsch cashdis equity].each do |field| - record.errors.add field, I18n.t("validations.financial.shared_ownership_deposit", - mortgage_deposit_and_discount_error_fields: record.mortgage_deposit_and_discount_error_fields, - mortgage_deposit_and_discount_total: record.field_formatted_as_currency("mortgage_deposit_and_discount_total"), - value_times_equity: record.field_formatted_as_currency("value_times_equity")) - end - end - end - def validate_equity_less_than_staircase_difference(record) return unless record.equity && record.stairbought && record.stairowned return unless record.saledate && record.form.start_year_after_2024? diff --git a/spec/models/validations/sales/financial_validations_spec.rb b/spec/models/validations/sales/financial_validations_spec.rb index e52387987..316c2d175 100644 --- a/spec/models/validations/sales/financial_validations_spec.rb +++ b/spec/models/validations/sales/financial_validations_spec.rb @@ -432,181 +432,6 @@ RSpec.describe Validations::Sales::FinancialValidations do end end - describe "#validate_shared_ownership_deposit" do - let(:record) { FactoryBot.create(:sales_log, saledate: now) } - - around do |example| - Timecop.freeze(now) do - Singleton.__init__(FormHandler) - example.run - end - Timecop.return - end - - context "with a log in the 24/25 collection year" do - let(:now) { Time.zone.local(2024, 4, 2) } - - it "does not add an error if MORTGAGE + DEPOSIT + CASHDIS are equal VALUE * EQUITY/100" do - record.mortgage = 1000 - record.deposit = 1000 - record.cashdis = 1000 - record.value = 3000 - record.equity = 100 - - financial_validator.validate_shared_ownership_deposit(record) - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["equity"]).to be_empty - end - - it "does not add an error if mortgage is used and no mortgage is given" do - record.mortgage = nil - record.deposit = 1000 - record.cashdis = 1000 - record.value = 3000 - record.equity = 100 - - financial_validator.validate_shared_ownership_deposit(record) - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["equity"]).to be_empty - end - - it "adds an error if mortgage is not used and no mortgage is given" do - record.mortgage = nil - record.mortgageused = 2 - record.deposit = 1000 - record.cashdis = 1000 - record.value = 3000 - record.equity = 100 - - financial_validator.validate_shared_ownership_deposit(record) - expect(record.errors["mortgage"]).to include("The mortgage, deposit, and cash discount added together is £2,000.00. The value times the equity percentage is £3,000.00. These figures should be the same") - expect(record.errors["deposit"]).to include("The mortgage, deposit, and cash discount added together is £2,000.00. The value times the equity percentage is £3,000.00. These figures should be the same") - expect(record.errors["cashdis"]).to include("The mortgage, deposit, and cash discount added together is £2,000.00. The value times the equity percentage is £3,000.00. These figures should be the same") - expect(record.errors["value"]).to include("The mortgage, deposit, and cash discount added together is £2,000.00. The value times the equity percentage is £3,000.00. These figures should be the same") - expect(record.errors["equity"]).to include("The mortgage, deposit, and cash discount added together is £2,000.00. The value times the equity percentage is £3,000.00. These figures should be the same") - end - - it "does not add an error if no deposit is given" do - record.mortgage = 1000 - record.deposit = nil - record.cashdis = 1000 - record.value = 3000 - record.equity = 100 - - financial_validator.validate_shared_ownership_deposit(record) - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["equity"]).to be_empty - end - - it "does not add an error if no cashdis is given and cashdis is routed to" do - record.mortgage = 1000 - record.deposit = 1000 - record.type = 18 - record.cashdis = nil - record.value = 3000 - record.equity = 100 - - financial_validator.validate_shared_ownership_deposit(record) - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["equity"]).to be_empty - end - - it "does not add an error if no cashdis is given and cashdis is not routed to" do - record.mortgageused = 1 - record.mortgage = 1000 - record.deposit = 1000 - record.type = 2 - record.cashdis = nil - record.value = 3000 - record.equity = 100 - - financial_validator.validate_shared_ownership_deposit(record) - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["equity"]).to be_empty - end - - it "does not add an error if no value is given" do - record.mortgage = 1000 - record.deposit = 1000 - record.cashdis = 1000 - record.value = nil - record.equity = 100 - - financial_validator.validate_shared_ownership_deposit(record) - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["equity"]).to be_empty - end - - it "does not add an error if no equity is given" do - record.mortgage = 1000 - record.deposit = 1000 - record.cashdis = 1000 - record.value = 3000 - record.equity = nil - - financial_validator.validate_shared_ownership_deposit(record) - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["equity"]).to be_empty - end - - it "adds an error if MORTGAGE + DEPOSIT + CASHDIS are not equal VALUE * EQUITY/100" do - record.mortgageused = 1 - record.mortgage = 1000 - record.deposit = 1000 - record.cashdis = 1000 - record.value = 4323 - record.equity = 100 - - financial_validator.validate_shared_ownership_deposit(record) - expect(record.errors["mortgage"]).to include("The mortgage, deposit, and cash discount added together is £3,000.00. The value times the equity percentage is £4,323.00. These figures should be the same") - expect(record.errors["deposit"]).to include("The mortgage, deposit, and cash discount added together is £3,000.00. The value times the equity percentage is £4,323.00. These figures should be the same") - expect(record.errors["cashdis"]).to include("The mortgage, deposit, and cash discount added together is £3,000.00. The value times the equity percentage is £4,323.00. These figures should be the same") - expect(record.errors["value"]).to include("The mortgage, deposit, and cash discount added together is £3,000.00. The value times the equity percentage is £4,323.00. These figures should be the same") - expect(record.errors["equity"]).to include("The mortgage, deposit, and cash discount added together is £3,000.00. The value times the equity percentage is £4,323.00. These figures should be the same") - end - end - - context "with a log in 23/24 collection year" do - let(:now) { Time.zone.local(2024, 1, 1) } - - it "does not add an error if MORTGAGE + DEPOSIT + CASHDIS are not equal VALUE * EQUITY/100" do - record.mortgage = 1000 - record.deposit = 1000 - record.cashdis = 1000 - record.value = 4323 - record.equity = 100 - - financial_validator.validate_shared_ownership_deposit(record) - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["equity"]).to be_empty - end - end - end - describe "#validate_equity_less_than_staircase_difference" do let(:record) { FactoryBot.create(:sales_log, saledate: now) }