From 0a393023635adb1b2feeb2fdcdbea0756f9c8899 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 18 Jan 2023 17:40:10 +0000 Subject: [PATCH] feat: add condition-less soft validation and update db --- .../pages/extra_borrowing_value_check.rb | 23 +++++++++++++++++++ .../questions/extra_borrowing_value_check.rb | 23 +++++++++++++++++++ .../discounted_ownership_scheme.rb | 1 + .../form/sales/subsections/outright_sale.rb | 1 + .../subsections/shared_ownership_scheme.rb | 1 + .../validations/sales/soft_validations.rb | 4 ++++ config/locales/en.yml | 3 +++ ...dd_extra_borrowing_value_check_to_sales.rb | 7 ++++++ db/schema.rb | 13 ++++++----- 9 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 app/models/form/sales/pages/extra_borrowing_value_check.rb create mode 100644 app/models/form/sales/questions/extra_borrowing_value_check.rb create mode 100644 db/migrate/20230118170602_add_extra_borrowing_value_check_to_sales.rb 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..5e7f9f10a --- /dev/null +++ b/app/models/form/sales/pages/extra_borrowing_value_check.rb @@ -0,0 +1,23 @@ +class Form::Sales::Pages::ExtraBorrowingValueCheck < Form::Page + def initialize(id, hsh, subsection) + super + @depends_on = [ + { + "extra_borrowing_expected?" => true, + }, + ] + @title_text = { + "translation" => "soft_validations.extra_borrowing.title", + } + @informative_text = { + "translation" => "soft_validations.extra_borrowing.hint_text", + "arguments" => [], + } + 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..a0bae0ba7 --- /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 this 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..9b58e4ab3 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb @@ -18,6 +18,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection 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_discounted_ownership", nil, self), Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", 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/form/sales/subsections/outright_sale.rb b/app/models/form/sales/subsections/outright_sale.rb index 82099dab6..9994a6d8f 100644 --- a/app/models/form/sales/subsections/outright_sale.rb +++ b/app/models/form/sales/subsections/outright_sale.rb @@ -15,6 +15,7 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_outright_sale", nil, self), Form::Sales::Pages::MortgageLength.new("mortgage_length_outright_sale", nil, self), Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_outright_sale", nil, self), + Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_value_check_outright_sale", nil, self), Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_outright_sale", nil, self), Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_value_check", nil, self), Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_outright_sale", nil, self), diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 8b5ff0902..28b24e887 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -26,6 +26,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_shared_ownership", nil, self), Form::Sales::Pages::MortgageLength.new("mortgage_length_shared_ownership", nil, self), Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_shared_ownership", nil, self), + Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_value_check_shared_ownership", nil, self), Form::Sales::Pages::AboutDepositWithDiscount.new(nil, nil, self), Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership", nil, self), Form::Sales::Pages::DepositValueCheck.new("shared_ownership_deposit_value_check", nil, self), diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index db061704d..719075c06 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -36,4 +36,8 @@ module Validations::Sales::SoftValidations deposit > savings * 4 / 3 end + + def extra_borrowing_expected? + true + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 788b3a710..a2d1a2eab 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -410,6 +410,9 @@ 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: "You told us this doesn't include any extra borrowing" + hint_text: "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 5b8e58122..86b0a633b 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_13_125117) 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" @@ -488,16 +488,17 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_13_125117) do t.integer "mortgagelender" t.string "mortgagelenderother" t.integer "mortlen" - t.string "pcode1" - t.string "pcode2" - t.integer "pcodenk" - t.string "postcode_full" - t.boolean "is_la_inferred" t.integer "extrabor" t.integer "hhmemb" t.integer "totadult" t.integer "totchild" t.integer "hhtype" + t.string "pcode1" + t.string "pcode2" + t.integer "pcodenk" + t.string "postcode_full" + t.boolean "is_la_inferred" + t.integer "extrabor_value_check" 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"