diff --git a/app/models/form/sales/pages/staircase_owned_value_check.rb b/app/models/form/sales/pages/staircase_owned_value_check.rb new file mode 100644 index 000000000..d83bf7d5d --- /dev/null +++ b/app/models/form/sales/pages/staircase_owned_value_check.rb @@ -0,0 +1,36 @@ +class Form::Sales::Pages::StaircaseOwnedValueCheck < ::Form::Page + def initialize(id, hsh, subsection, joint_purchase:) + super(id, hsh, subsection) + @joint_purchase = joint_purchase + @depends_on = [ + { + "staircase_owned_out_of_soft_range?" => true, + "joint_purchase?" => joint_purchase, + }, + ] + @title_text = { + "translation" => joint_purchase ? "soft_validations.staircase_owned.title_text.two" : "soft_validations.staircase_owned.title_text.one", + "arguments" => [ + { + "key" => "stairowned", + "label" => true, + "i18n_template" => "stairowned", + }, + ], + } + @informative_text = { + "translation" => "soft_validations.staircase_owned.hint_text", + "arguments" => [], + } + end + + def questions + @questions ||= [ + Form::Sales::Questions::StaircaseOwnedValueCheck.new(nil, nil, self), + ] + end + + def interruption_screen_question_ids + %w[type stairowned] + end +end diff --git a/app/models/form/sales/questions/staircase_owned_value_check.rb b/app/models/form/sales/questions/staircase_owned_value_check.rb new file mode 100644 index 000000000..eb742b196 --- /dev/null +++ b/app/models/form/sales/questions/staircase_owned_value_check.rb @@ -0,0 +1,23 @@ +class Form::Sales::Questions::StaircaseOwnedValueCheck < ::Form::Question + def initialize(id, hsh, page) + super + @id = "stairowned_value_check" + @check_answer_label = "Percentage owned confirmation" + @header = "Are you sure?" + @type = "interruption_screen" + @answer_options = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + } + @hidden_in_check_answers = { + "depends_on" => [ + { + "stairowned_value_check" => 0, + }, + { + "stairowned_value_check" => 1, + }, + ], + } + 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 b122faf63..66a711dcd 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -13,6 +13,8 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::AboutStaircase.new("about_staircasing_joint_purchase", nil, self, joint_purchase: true), Form::Sales::Pages::AboutStaircase.new("about_staircasing_not_joint_purchase", nil, self, joint_purchase: false), Form::Sales::Pages::StaircaseBoughtValueCheck.new(nil, nil, self), + Form::Sales::Pages::StaircaseOwnedValueCheck.new("staircase_owned_value_check_joint_purchase", nil, self, joint_purchase: true), + Form::Sales::Pages::StaircaseOwnedValueCheck.new("staircase_owned_value_check_not_joint_purchase", nil, self, joint_purchase: false), Form::Sales::Pages::Resale.new(nil, nil, self), Form::Sales::Pages::ExchangeDate.new(nil, nil, self), Form::Sales::Pages::HandoverDate.new(nil, nil, self), diff --git a/app/models/validations/sales/financial_validations.rb b/app/models/validations/sales/financial_validations.rb index 02fceeadc..ffdee561a 100644 --- a/app/models/validations/sales/financial_validations.rb +++ b/app/models/validations/sales/financial_validations.rb @@ -76,15 +76,6 @@ module Validations::Sales::FinancialValidations end end - def validate_percentage_owned_not_too_much_if_older_person(record) - return unless record.old_persons_shared_ownership? && record.stairowned - - if record.stairowned > 75 - record.errors.add :stairowned, I18n.t("validations.financial.staircasing.older_person_percentage_owned_maximum_75") - record.errors.add :type, I18n.t("validations.financial.staircasing.older_person_percentage_owned_maximum_75") - end - end - def validate_equity_in_range_for_year_and_type(record) return unless record.type && record.equity && record.collection_start_year diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index 35f463f63..52a89550a 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -77,6 +77,12 @@ module Validations::Sales::SoftValidations !value.between?(sale_range.soft_min, sale_range.soft_max) end + def staircase_owned_out_of_soft_range? + return unless type && stairowned + + type == 24 && stairowned.between?(76, 100) + end + def shared_ownership_deposit_invalid? return unless mortgage || mortgageused == 2 || mortgageused == 3 return unless cashdis || !is_type_discount? diff --git a/config/locales/en.yml b/config/locales/en.yml index 73cf91d0a..915ff825a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -390,7 +390,6 @@ en: cash_discount_invalid: "Cash discount must be £0 - £999,999" staircasing: percentage_bought_must_be_greater_than_percentage_owned: "Total percentage buyer now owns must be more than percentage bought in this transaction" - older_person_percentage_owned_maximum_75: "Percentage cannot be above 75% under Older Person's Shared Ownership" percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{threshold}%" monthly_leasehold_charges: not_zero: "Monthly leasehold charges cannot be £0 if the property has monthly charges" @@ -600,6 +599,12 @@ en: purchase_price: title_text: "You told us the purchase price is %{value}" hint_text: "This is %{higher_or_lower} than we would expect" + staircase_owned: + title_text: + one: "You told us that the buyer now owns %{stairowned} of the property" + two: "You told us that the buyers now own %{stairowned} of the property" + hint_text: "The maximum percentage that can be owned under the Older Persons Shared Ownership scheme is 75%, unless the property was funded outside the Affordable Homes Programme. +Make sure these answers are correct." retirement: min: title: "You told us this person is aged %{age} years and retired." diff --git a/db/schema.rb b/db/schema.rb index 1bbbba02a..d071b20db 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_06_09_101144) do +ActiveRecord::Schema[7.0].define(version: 2023_06_21_142422) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -604,6 +604,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_09_101144) do t.integer "status_cache", default: 0, null: false t.integer "combined_income_value_check" t.datetime "discarded_at" + t.integer "stairowned_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 ["old_id"], name: "index_sales_logs_on_old_id", unique: true diff --git a/spec/models/validations/sales/financial_validations_spec.rb b/spec/models/validations/sales/financial_validations_spec.rb index 7b3740101..ab41885ff 100644 --- a/spec/models/validations/sales/financial_validations_spec.rb +++ b/spec/models/validations/sales/financial_validations_spec.rb @@ -214,36 +214,6 @@ RSpec.describe Validations::Sales::FinancialValidations do end end - describe "#validate_percentage_owned_not_too_much_if_older_person" do - let(:record) { FactoryBot.create(:sales_log) } - - context "when log type is not older persons shared ownership" do - it "does not add an error when percentage owned after staircasing transaction exceeds 75%" do - record.type = 2 - record.stairowned = 80 - financial_validator.validate_percentage_owned_not_too_much_if_older_person(record) - expect(record.errors).to be_empty - end - end - - context "when log type is older persons shared ownership" do - it "does not add an error when percentage owned after staircasing transaction is less than 75%" do - record.type = 24 - record.stairowned = 50 - financial_validator.validate_percentage_owned_not_too_much_if_older_person(record) - expect(record.errors).to be_empty - end - - it "adds an error when percentage owned after staircasing transaction exceeds 75%" do - record.type = 24 - record.stairowned = 90 - financial_validator.validate_percentage_owned_not_too_much_if_older_person(record) - expect(record.errors["stairowned"]).to include(match I18n.t("validations.financial.staircasing.older_person_percentage_owned_maximum_75")) - expect(record.errors["type"]).to include(match I18n.t("validations.financial.staircasing.older_person_percentage_owned_maximum_75")) - end - end - end - describe "#validate_child_income" do let(:record) { FactoryBot.create(:sales_log) }