diff --git a/app/models/form/sales/pages/extra_borrowing_value_check.rb b/app/models/form/sales/pages/extra_borrowing_value_check.rb new file mode 100644 index 000000000..18f975b8d --- /dev/null +++ b/app/models/form/sales/pages/extra_borrowing_value_check.rb @@ -0,0 +1,21 @@ +class Form::Sales::Pages::ExtraBorrowingValueCheck < Form::Page + def initialize(id, hsh, subsection) + super + @depends_on = [ + { + "extra_borrowing_expected_but_not_reported?" => true, + }, + ] + @title_text = { + "translation" => "soft_validations.extra_borrowing.title", + } + @informative_text = { + } + end + + def questions + @questions ||= [ + Form::Sales::Questions::ExtraBorrowingValueCheck.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/extra_borrowing_value_check.rb b/app/models/form/sales/questions/extra_borrowing_value_check.rb new file mode 100644 index 000000000..0f12ce110 --- /dev/null +++ b/app/models/form/sales/questions/extra_borrowing_value_check.rb @@ -0,0 +1,23 @@ +class Form::Sales::Questions::ExtraBorrowingValueCheck < ::Form::Question + def initialize(id, hsh, page) + super(id, hsh, page) + @id = "extrabor_value_check" + @check_answer_label = "Extra borrowing confirmation" + @type = "interruption_screen" + @answer_options = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + } + @hidden_in_check_answers = { + "depends_on" => [ + { + "extrabor_value_check" => 0, + }, + { + "extrabor_value_check" => 1, + }, + ], + } + @header = "Are you sure there is no extra borrowing?" + end +end diff --git a/app/models/form/sales/subsections/discounted_ownership_scheme.rb b/app/models/form/sales/subsections/discounted_ownership_scheme.rb index b527cd7d4..3b994d931 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb @@ -10,15 +10,19 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection @pages ||= [ Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_discounted_ownership", nil, self), Form::Sales::Pages::AboutPriceRtb.new(nil, nil, self), + Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_price_value_check", nil, self), Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self), Form::Sales::Pages::PurchasePrice.new("purchase_price_discounted_ownership", nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self), + Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_mortgage_value_check", nil, self), Form::Sales::Pages::MortgageLender.new("mortgage_lender_discounted_ownership", nil, self), Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_discounted_ownership", nil, self), Form::Sales::Pages::MortgageLength.new("mortgage_length_discounted_ownership", nil, self), Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_discounted_ownership", nil, self), + Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_value_check", nil, self), Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", nil, self), + Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_deposit_value_check", nil, self), Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self), Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_discounted_ownership", nil, self), ] diff --git a/app/models/validations/sales/household_validations.rb b/app/models/validations/sales/household_validations.rb index 42846273c..8c03d9db9 100644 --- a/app/models/validations/sales/household_validations.rb +++ b/app/models/validations/sales/household_validations.rb @@ -109,10 +109,6 @@ private economic_status == 7 end - def person_economic_status_refused?(economic_status) - economic_status == 10 - end - def person_is_child?(relationship) relationship == "C" end diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index 19c2a13ec..e39b5e9d9 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -37,6 +37,12 @@ module Validations::Sales::SoftValidations deposit > savings * 4 / 3 end + def extra_borrowing_expected_but_not_reported? + return unless extrabor && mortgage && deposit && value && discount + + extrabor != 1 && mortgage + deposit > value - value * discount / 100 + end + def hodate_3_years_or_more_saledate? return unless hodate && saledate diff --git a/config/locales/en.yml b/config/locales/en.yml index c988d2dd9..0be594420 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -448,6 +448,8 @@ en: max: title: "You told us this person is %{age} or over and not retired" hint_text: "The minimum expected retirement age for %{gender} in England is %{age}." + extra_borrowing: + title: "The mortgage and deposit are higher than the purchase minus the discount" pregnancy: title: "You told us somebody in the household is pregnant" no_females: "You also told us there are no female tenants living at the property." diff --git a/db/migrate/20230118170602_add_extra_borrowing_value_check_to_sales.rb b/db/migrate/20230118170602_add_extra_borrowing_value_check_to_sales.rb new file mode 100644 index 000000000..ce4e79718 --- /dev/null +++ b/db/migrate/20230118170602_add_extra_borrowing_value_check_to_sales.rb @@ -0,0 +1,7 @@ +class AddExtraBorrowingValueCheckToSales < ActiveRecord::Migration[7.0] + def change + change_table :sales_logs, bulk: true do |t| + t.column :extrabor_value_check, :integer + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 91c6bed37..e97d4a5ac 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_01_16_151942) do +ActiveRecord::Schema[7.0].define(version: 2023_01_18_170602) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -502,8 +502,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_16_151942) do t.integer "hhtype" t.integer "hodate_check" t.bigint "bulk_upload_id" - t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id" t.integer "retirement_value_check" + t.integer "extrabor_value_check" + t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" diff --git a/db/seeds.rb b/db/seeds.rb index 8dea68d80..6a4098f9b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -160,7 +160,7 @@ unless Rails.env.test? saledate: Date.new(1, 1, 1), purchid: "1", ownershipsch: 2, - type: 8, + type: 9, jointpur: 1, jointmore: 1, ) diff --git a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb index 632ba85bc..44896a0f9 100644 --- a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb @@ -16,15 +16,19 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model %w[ living_before_purchase_discounted_ownership about_price_rtb + extra_borrowing_price_value_check about_price_not_rtb purchase_price_discounted_ownership mortgage_used_discounted_ownership mortgage_amount_discounted_ownership + extra_borrowing_mortgage_value_check mortgage_lender_discounted_ownership mortgage_lender_other_discounted_ownership mortgage_length_discounted_ownership extra_borrowing_discounted_ownership + extra_borrowing_value_check about_deposit_discounted_ownership + extra_borrowing_deposit_value_check discounted_ownership_deposit_value_check leasehold_charges_discounted_ownership ], diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 965e79690..8f9a88f7f 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -52,14 +52,14 @@ RSpec.describe FormHandler do it "is able to load a current sales form" do form = form_handler.get_form("current_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(183) + expect(form.pages.count).to eq(187) expect(form.name).to eq("2022_2023_sales") end it "is able to load a previous sales form" do form = form_handler.get_form("previous_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(183) + expect(form.pages.count).to eq(187) expect(form.name).to eq("2021_2022_sales") end end diff --git a/spec/models/validations/sales/soft_validations_spec.rb b/spec/models/validations/sales/soft_validations_spec.rb index 34f49d847..17bd87d96 100644 --- a/spec/models/validations/sales/soft_validations_spec.rb +++ b/spec/models/validations/sales/soft_validations_spec.rb @@ -128,7 +128,7 @@ RSpec.describe Validations::Sales::SoftValidations do .not_to be_mortgage_over_soft_max end - it "returns true if only income1 is used for morgage and it is less than 1/5 of the morgage" do + it "returns true if only income1 is used for mortgage and it is less than 1/5 of the mortgage" do record.inc1mort = 1 record.income1 = 10_000 record.mortgage = 51_000 @@ -137,7 +137,7 @@ RSpec.describe Validations::Sales::SoftValidations do .to be_mortgage_over_soft_max end - it "returns false if only income1 is used for morgage and it is more than 1/5 of the morgage" do + it "returns false if only income1 is used for mortgage and it is more than 1/5 of the mortgage" do record.inc1mort = 1 record.income1 = 10_000 record.mortgage = 44_000 @@ -146,7 +146,7 @@ RSpec.describe Validations::Sales::SoftValidations do .not_to be_mortgage_over_soft_max end - it "returns true if only income2 is used for morgage and it is less than 1/5 of the morgage" do + it "returns true if only income2 is used for mortgage and it is less than 1/5 of the mortgage" do record.inc1mort = 2 record.inc2mort = 1 record.income2 = 10_000 @@ -155,7 +155,7 @@ RSpec.describe Validations::Sales::SoftValidations do .to be_mortgage_over_soft_max end - it "returns false if only income2 is used for morgage and it is more than 1/5 of the morgage" do + it "returns false if only income2 is used for mortgage and it is more than 1/5 of the mortgage" do record.inc1mort = 2 record.inc2mort = 1 record.income2 = 10_000 @@ -164,7 +164,7 @@ RSpec.describe Validations::Sales::SoftValidations do .not_to be_mortgage_over_soft_max end - it "returns true if income1 and income2 are used for morgage and their sum is less than 1/5 of the morgage" do + it "returns true if income1 and income2 are used for mortgage and their sum is less than 1/5 of the mortgage" do record.inc1mort = 1 record.inc2mort = 1 record.income1 = 10_000 @@ -174,7 +174,7 @@ RSpec.describe Validations::Sales::SoftValidations do .to be_mortgage_over_soft_max end - it "returns false if income1 and income2 are used for morgage and their sum is more than 1/5 of the morgage" do + it "returns false if income1 and income2 are used for mortgage and their sum is more than 1/5 of the mortgage" do record.inc1mort = 1 record.inc2mort = 1 record.income1 = 8_000 @@ -184,7 +184,7 @@ RSpec.describe Validations::Sales::SoftValidations do .not_to be_mortgage_over_soft_max end - it "returns true if neither of the incomes are used for morgage and the morgage is more than 0" do + it "returns true if neither of the incomes are used for mortgage and the mortgage is more than 0" do record.inc1mort = 2 record.inc2mort = 2 record.mortgage = 124_000 @@ -192,7 +192,7 @@ RSpec.describe Validations::Sales::SoftValidations do .to be_mortgage_over_soft_max end - it "returns true if neither of the incomes are used for morgage and the morgage is 0" do + it "returns false if neither of the incomes are used for mortgage and the mortgage is 0" do record.inc1mort = 2 record.inc2mort = 2 record.mortgage = 0 @@ -200,6 +200,73 @@ RSpec.describe Validations::Sales::SoftValidations do .not_to be_mortgage_over_soft_max end end + + context "when validating extra borrowing" do + it "returns false if extrabor not present" do + record.mortgage = 50_000 + record.deposit = 40_000 + record.value = 100_000 + record.discount = 11 + expect(record) + .not_to be_extra_borrowing_expected_but_not_reported + end + + it "returns false if mortgage not present" do + record.extrabor = 2 + record.deposit = 40_000 + record.value = 100_000 + record.discount = 11 + expect(record) + .not_to be_extra_borrowing_expected_but_not_reported + end + + it "returns false if deposit not present" do + record.extrabor = 2 + record.mortgage = 50_000 + record.value = 100_000 + record.discount = 11 + expect(record) + .not_to be_extra_borrowing_expected_but_not_reported + end + + it "returns false if value not present" do + record.extrabor = 2 + record.mortgage = 50_000 + record.deposit = 40_000 + record.discount = 11 + expect(record) + .not_to be_extra_borrowing_expected_but_not_reported + end + + it "returns false if discount not present" do + record.extrabor = 2 + record.mortgage = 50_000 + record.deposit = 40_000 + record.value = 100_000 + expect(record) + .not_to be_extra_borrowing_expected_but_not_reported + end + + it "returns false if extra borrowing expected and reported" do + record.extrabor = 1 + record.mortgage = 50_000 + record.deposit = 40_000 + record.value = 100_000 + record.discount = 11 + expect(record) + .not_to be_extra_borrowing_expected_but_not_reported + end + + it "returns true if extra borrowing expected but not reported" do + record.extrabor = 2 + record.mortgage = 50_000 + record.deposit = 40_000 + record.value = 100_000 + record.discount = 11 + expect(record) + .to be_extra_borrowing_expected_but_not_reported + end + end end describe "savings amount validations" do