From d2cd5b0b0af728d2abe4a32fa12f0efe2f2dccb6 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Tue, 24 Jan 2023 08:55:53 +0000 Subject: [PATCH] feat: wip behaviour --- ...bout_price_shared_ownership_value_check.rb | 18 +++++++++++++ ...bout_price_shared_ownership_value_check.rb | 27 +++++++++++++++++++ .../subsections/shared_ownership_scheme.rb | 1 + .../validations/sales/soft_validations.rb | 6 +++++ ...ared_ownership_value_check_to_sales_log.rb | 5 ++++ db/schema.rb | 4 ++- 6 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 app/models/form/sales/pages/about_price_shared_ownership_value_check.rb create mode 100644 app/models/form/sales/questions/about_price_shared_ownership_value_check.rb create mode 100644 db/migrate/20230123171907_add_about_price_shared_ownership_value_check_to_sales_log.rb diff --git a/app/models/form/sales/pages/about_price_shared_ownership_value_check.rb b/app/models/form/sales/pages/about_price_shared_ownership_value_check.rb new file mode 100644 index 000000000..8cd3fffe8 --- /dev/null +++ b/app/models/form/sales/pages/about_price_shared_ownership_value_check.rb @@ -0,0 +1,18 @@ +class Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "about_price_shared_ownership_value_check" + @depends_on = [ + { + "purchase_price_out_of_expected_range?" => true, + }, + ] + @informative_text = {} + end + + def questions + @questions ||= [ + Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/about_price_shared_ownership_value_check.rb b/app/models/form/sales/questions/about_price_shared_ownership_value_check.rb new file mode 100644 index 000000000..8b8e8e269 --- /dev/null +++ b/app/models/form/sales/questions/about_price_shared_ownership_value_check.rb @@ -0,0 +1,27 @@ +class Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck < ::Form::Question + def initialize(id, hsh, page) + super + @id = "value_value_check" + @check_answer_label = "Deposit confirmation" + @header = "Are you sure? You said purchase price was #{log.value}, which seems #{value_is_high?(log.value) ? 'high' : 'low'}" + @type = "interruption_screen" + @answer_options = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + } + @hidden_in_check_answers = { + "depends_on" => [ + { + "value_value_check" => 0, + }, + { + "value_value_check" => 1, + }, + ], + } + end + + def value_is_high?(value) + true + end +end diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 8c05cd82d..02c38994b 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -21,6 +21,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::PreviousPropertyType.new(nil, nil, self), Form::Sales::Pages::PreviousTenure.new(nil, nil, self), Form::Sales::Pages::AboutPriceSharedOwnership.new(nil, nil, self), + Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck.new(nil, nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_shared_ownership", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self), Form::Sales::Pages::MortgageLender.new("mortgage_lender_shared_ownership", nil, self), diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index 3deb92aaa..3bc9dab1f 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -42,4 +42,10 @@ module Validations::Sales::SoftValidations ((saledate.to_date - hodate.to_date).to_i / 365) >= 3 end + + def purchase_price_out_of_expected_range? + return unless value + + true + end end diff --git a/db/migrate/20230123171907_add_about_price_shared_ownership_value_check_to_sales_log.rb b/db/migrate/20230123171907_add_about_price_shared_ownership_value_check_to_sales_log.rb new file mode 100644 index 000000000..f8e03c59f --- /dev/null +++ b/db/migrate/20230123171907_add_about_price_shared_ownership_value_check_to_sales_log.rb @@ -0,0 +1,5 @@ +class AddAboutPriceSharedOwnershipValueCheckToSalesLog < ActiveRecord::Migration[7.0] + def change + add_column :sales_logs, :value_value_check, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 9e02d77e4..624b38769 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_23_171907) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -499,6 +499,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_16_151942) do t.string "postcode_full" t.boolean "is_la_inferred" t.integer "hodate_check" + t.integer "extrabor_value_check" + t.integer "value_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"