From 4454a815de6e3999959a719710ba6ce349e244b9 Mon Sep 17 00:00:00 2001 From: samyou-softwire Date: Wed, 22 Apr 2026 12:18:34 +0100 Subject: [PATCH] CLDC-3676: sales discounted sale soft validation --- .../pages/discounted_sale_value_check.rb | 43 ------ .../questions/discounted_sale_value_check.rb | 22 ---- .../discounted_ownership_scheme.rb | 5 - .../validations/sales/soft_validations.rb | 9 -- .../pages/discounted_sale_value_check_spec.rb | 53 -------- .../discounted_sale_value_check_spec.rb | 45 ------- .../discounted_ownership_scheme_spec.rb | 55 -------- .../sales/soft_validations_spec.rb | 123 ------------------ 8 files changed, 355 deletions(-) delete mode 100644 app/models/form/sales/pages/discounted_sale_value_check.rb delete mode 100644 app/models/form/sales/questions/discounted_sale_value_check.rb delete mode 100644 spec/models/form/sales/pages/discounted_sale_value_check_spec.rb delete mode 100644 spec/models/form/sales/questions/discounted_sale_value_check_spec.rb diff --git a/app/models/form/sales/pages/discounted_sale_value_check.rb b/app/models/form/sales/pages/discounted_sale_value_check.rb deleted file mode 100644 index 4fbff90c6..000000000 --- a/app/models/form/sales/pages/discounted_sale_value_check.rb +++ /dev/null @@ -1,43 +0,0 @@ -class Form::Sales::Pages::DiscountedSaleValueCheck < ::Form::Page - def initialize(id, hsh, subsection, person_index = nil) - super(id, hsh, subsection) - @depends_on = depends_on - @copy_key = "sales.soft_validations.discounted_sale_value_check" - @title_text = { - "translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text", - "arguments" => [ - { - "key" => "field_formatted_as_currency", - "arguments_for_key" => "value_with_discount", - "i18n_template" => "value_with_discount", - }, - ], - } - @informative_text = { - "translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text", - "arguments" => [ - { - "key" => "field_formatted_as_currency", - "arguments_for_key" => "mortgage_deposit_and_grant_total", - "i18n_template" => "mortgage_deposit_and_grant_total", - }, - ], - } - @person_index = person_index - @depends_on = [ - { - "discounted_ownership_value_invalid?" => true, - }, - ] - end - - def questions - @questions ||= [ - Form::Sales::Questions::DiscountedSaleValueCheck.new(nil, nil, self), - ] - end - - def interruption_screen_question_ids - %w[value deposit ownershipsch mortgage mortgageused discount grant type] - end -end diff --git a/app/models/form/sales/questions/discounted_sale_value_check.rb b/app/models/form/sales/questions/discounted_sale_value_check.rb deleted file mode 100644 index a02aaac72..000000000 --- a/app/models/form/sales/questions/discounted_sale_value_check.rb +++ /dev/null @@ -1,22 +0,0 @@ -class Form::Sales::Questions::DiscountedSaleValueCheck < ::Form::Question - def initialize(id, hsh, page) - super - @id = "discounted_sale_value_check" - @copy_key = "sales.soft_validations.discounted_sale_value_check" - @type = "interruption_screen" - @answer_options = { - "0" => { "value" => "Yes" }, - "1" => { "value" => "No" }, - } - @hidden_in_check_answers = { - "depends_on" => [ - { - "discounted_sale_value_check" => 0, - }, - { - "discounted_sale_value_check" => 1, - }, - ], - } - 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 dea8334b8..6577c5408 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb @@ -18,16 +18,12 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::Grant.new(nil, nil, self), Form::Sales::Pages::GrantValueCheck.new(nil, nil, self), Form::Sales::Pages::PurchasePriceOutrightOwnership.new("purchase_price_discounted_ownership", nil, self, ownershipsch: 2), - Form::Sales::Pages::DiscountedSaleValueCheck.new("discounted_sale_grant_value_check", nil, self), Form::Sales::Pages::AboutPriceValueCheck.new("about_price_discounted_ownership_value_check", nil, self), Form::Sales::Pages::DepositAndMortgageValueCheck.new("discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount", nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self, ownershipsch: 2), Form::Sales::Pages::MortgageValueCheck.new("discounted_ownership_mortgage_used_mortgage_value_check", nil, self), - Form::Sales::Pages::DiscountedSaleValueCheck.new("discounted_sale_mortgage_used_value_check", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self, ownershipsch: 2), Form::Sales::Pages::MortgageValueCheck.new("discounted_ownership_mortgage_amount_mortgage_value_check", nil, self), - Form::Sales::Pages::DiscountedSaleValueCheck.new("discounted_sale_mortgage_value_check", nil, self), - Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_mortgage_value_check", nil, self), Form::Sales::Pages::DepositAndMortgageValueCheck.new("discounted_ownership_deposit_and_mortgage_value_check_after_mortgage", nil, self), mortgage_lender_questions, (Form::Sales::Pages::MortgageLength.new("mortgage_length_discounted_ownership", nil, self, ownershipsch: 2) unless form.start_year_2026_or_later?), @@ -40,7 +36,6 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_joint_purchase_value_check", nil, self, joint_purchase: true), Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self, joint_purchase: false), Form::Sales::Pages::DepositAndMortgageValueCheck.new("discounted_ownership_deposit_and_mortgage_value_check_after_deposit", nil, self), - Form::Sales::Pages::DiscountedSaleValueCheck.new("discounted_sale_deposit_value_check", nil, self), Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_discounted_ownership", nil, self, ownershipsch: 2), Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_discounted_ownership_value_check", nil, self), ].flatten.compact diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index 5abca6586..77a5f77a5 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -159,15 +159,6 @@ module Validations::Sales::SoftValidations end end - def discounted_ownership_value_invalid? - return unless saledate && collection_start_year <= 2023 - return unless value && deposit && ownershipsch - return unless mortgage || mortgageused == 2 || mortgageused == 3 - return unless discount || grant || type == 29 - - mortgage_deposit_and_grant_total != value_with_discount && discounted_ownership_sale? - end - def buyer1_livein_wrong_for_ownership_type? return unless ownershipsch && buy1livein diff --git a/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb b/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb deleted file mode 100644 index b140372db..000000000 --- a/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Pages::DiscountedSaleValueCheck, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection, index) } - - let(:page_id) { "discounted_sale_value_check" } - let(:page_definition) { nil } - let(:index) { 1 } - let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) } - let(:subsection) { instance_double(Form::Subsection, form:) } - - it "has correct subsection" do - expect(page.subsection).to eq(subsection) - end - - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[discounted_sale_value_check]) - end - - it "has the correct id" do - expect(page.id).to eq("discounted_sale_value_check") - end - - it "has the correct title_text" do - expect(page.title_text).to eq({ - "translation" => "forms.2024.sales.soft_validations.discounted_sale_value_check.title_text", - "arguments" => [{ "arguments_for_key" => "value_with_discount", "i18n_template" => "value_with_discount", "key" => "field_formatted_as_currency" }], - }) - end - - it "has the correct informative_text" do - expect(page.informative_text).to eq({ - "translation" => "forms.2024.sales.soft_validations.discounted_sale_value_check.informative_text", - "arguments" => [{ "arguments_for_key" => "mortgage_deposit_and_grant_total", "i18n_template" => "mortgage_deposit_and_grant_total", "key" => "field_formatted_as_currency" }], - }) - end - - it "is interruption screen page" do - expect(page.interruption_screen?).to be(true) - end - - it "has correct depends_on" do - expect(page.depends_on).to eq([ - { - "discounted_ownership_value_invalid?" => true, - }, - ]) - end - - it "has correct interruption_screen_question_ids" do - expect(page.interruption_screen_question_ids).to eq(%w[value deposit ownershipsch mortgage mortgageused discount grant type]) - end -end diff --git a/spec/models/form/sales/questions/discounted_sale_value_check_spec.rb b/spec/models/form/sales/questions/discounted_sale_value_check_spec.rb deleted file mode 100644 index 09170a225..000000000 --- a/spec/models/form/sales/questions/discounted_sale_value_check_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Questions::DiscountedSaleValueCheck, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } - - let(:question_id) { nil } - let(:question_definition) { nil } - let(:page) { instance_double(Form::Page) } - - it "has correct page" do - expect(question.page).to eq(page) - end - - it "has the correct id" do - expect(question.id).to eq("discounted_sale_value_check") - end - - it "has the correct type" do - expect(question.type).to eq("interruption_screen") - end - - it "is not marked as derived" do - expect(question.derived?(nil)).to be false - end - - it "has the correct answer_options" do - expect(question.answer_options).to eq({ - "0" => { "value" => "Yes" }, - "1" => { "value" => "No" }, - }) - end - - it "has the correct hidden_in_check_answers" do - expect(question.hidden_in_check_answers).to eq({ - "depends_on" => [ - { - "discounted_sale_value_check" => 0, - }, - { - "discounted_sale_value_check" => 1, - }, - ], - }) - end -end 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 dc91a8f92..456294f2c 100644 --- a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb @@ -52,51 +52,6 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model end end - context "when 2024", metadata: { year: 24 } do - let(:start_year_2025_or_later?) { false } - let(:start_year_2026_or_later?) { false } - - it "has correct pages" do - expect(discounted_ownership_scheme.pages.map(&:id)).to eq( - %w[ - living_before_purchase_discounted_ownership_joint_purchase - living_before_purchase_discounted_ownership - purchase_price - discount - extra_borrowing_price_value_check - percentage_discount_value_check - grant - grant_value_check - purchase_price_discounted_ownership - discounted_sale_grant_value_check - about_price_discounted_ownership_value_check - discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount - mortgage_used_discounted_ownership - discounted_ownership_mortgage_used_mortgage_value_check - discounted_sale_mortgage_used_value_check - mortgage_amount_discounted_ownership - discounted_ownership_mortgage_amount_mortgage_value_check - discounted_sale_mortgage_value_check - extra_borrowing_mortgage_value_check - discounted_ownership_deposit_and_mortgage_value_check_after_mortgage - mortgage_lender_discounted_ownership - mortgage_lender_other_discounted_ownership - mortgage_length_discounted_ownership - extra_borrowing_discounted_ownership - extra_borrowing_value_check - deposit_discounted_ownership - extra_borrowing_deposit_value_check - discounted_ownership_deposit_joint_purchase_value_check - discounted_ownership_deposit_value_check - discounted_ownership_deposit_and_mortgage_value_check_after_deposit - discounted_sale_deposit_value_check - leasehold_charges_discounted_ownership - monthly_charges_discounted_ownership_value_check - ], - ) - end - end - context "when 2025", metadata: { year: 25 } do let(:start_year_2026_or_later?) { false } @@ -112,16 +67,12 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model grant grant_value_check purchase_price_discounted_ownership - discounted_sale_grant_value_check about_price_discounted_ownership_value_check discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount mortgage_used_discounted_ownership discounted_ownership_mortgage_used_mortgage_value_check - discounted_sale_mortgage_used_value_check mortgage_amount_discounted_ownership discounted_ownership_mortgage_amount_mortgage_value_check - discounted_sale_mortgage_value_check - extra_borrowing_mortgage_value_check discounted_ownership_deposit_and_mortgage_value_check_after_mortgage mortgage_length_discounted_ownership extra_borrowing_discounted_ownership @@ -131,7 +82,6 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model discounted_ownership_deposit_joint_purchase_value_check discounted_ownership_deposit_value_check discounted_ownership_deposit_and_mortgage_value_check_after_deposit - discounted_sale_deposit_value_check leasehold_charges_discounted_ownership monthly_charges_discounted_ownership_value_check ], @@ -152,16 +102,12 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model grant grant_value_check purchase_price_discounted_ownership - discounted_sale_grant_value_check about_price_discounted_ownership_value_check discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount mortgage_used_discounted_ownership discounted_ownership_mortgage_used_mortgage_value_check - discounted_sale_mortgage_used_value_check mortgage_amount_discounted_ownership discounted_ownership_mortgage_amount_mortgage_value_check - discounted_sale_mortgage_value_check - extra_borrowing_mortgage_value_check discounted_ownership_deposit_and_mortgage_value_check_after_mortgage mortgage_length_discounted_ownership_not_interviewed mortgage_length_discounted_ownership_interviewed @@ -172,7 +118,6 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model discounted_ownership_deposit_joint_purchase_value_check discounted_ownership_deposit_value_check discounted_ownership_deposit_and_mortgage_value_check_after_deposit - discounted_sale_deposit_value_check leasehold_charges_discounted_ownership monthly_charges_discounted_ownership_value_check ], diff --git a/spec/models/validations/sales/soft_validations_spec.rb b/spec/models/validations/sales/soft_validations_spec.rb index ba8ade724..0622e8283 100644 --- a/spec/models/validations/sales/soft_validations_spec.rb +++ b/spec/models/validations/sales/soft_validations_spec.rb @@ -961,129 +961,6 @@ RSpec.describe Validations::Sales::SoftValidations do end end - describe "#discounted_ownership_value_invalid?" do - context "when grant is routed to" do - let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, deposit: 5_000, value: 30_000, ownershipsch: 2, type: 8, saledate: Time.zone.local(2023, 4, 3)) } - - context "and not provided" do - before do - record.grant = nil - end - - it "returns false" do - expect(record).not_to be_discounted_ownership_value_invalid - end - end - - context "and is provided" do - it "returns true if mortgage, deposit and grant total does not equal market value" do - record.grant = 3_000 - expect(record).to be_discounted_ownership_value_invalid - end - - it "returns false if mortgage, deposit and grant total equals market value" do - record.grant = 15_000 - expect(record).not_to be_discounted_ownership_value_invalid - end - end - end - - context "when discount is routed to" do - let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, deposit: 5_000, value: 30_000, ownershipsch: 2, type: 9, saledate: Time.zone.local(2023, 4, 3)) } - - context "and not provided" do - before do - record.discount = nil - end - - it "returns false" do - expect(record).not_to be_discounted_ownership_value_invalid - end - end - - context "and is provided" do - it "returns true if mortgage and deposit total does not equal market value - discount" do - record.discount = 10 - expect(record).to be_discounted_ownership_value_invalid - end - - it "returns false if mortgage and deposit total equals market value - discount" do - record.discount = 50 - expect(record).not_to be_discounted_ownership_value_invalid - end - end - end - - context "when neither discount nor grant is routed to" do - let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, value: 30_000, ownershipsch: 2, type: 29, saledate: Time.zone.local(2023, 4, 3)) } - - it "returns true if mortgage and deposit total does not equal market value" do - record.deposit = 2_000 - expect(record).to be_discounted_ownership_value_invalid - end - - it "returns false if mortgage and deposit total equals market value" do - record.deposit = 20_000 - expect(record).not_to be_discounted_ownership_value_invalid - end - end - - context "when mortgage is routed to" do - let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, deposit: 5_000, grant: 3_000, value: 20_000, discount: 10, ownershipsch: 2, saledate: Time.zone.local(2023, 4, 3)) } - - context "and not provided" do - before do - record.mortgage = nil - end - - it "returns false" do - expect(record).not_to be_discounted_ownership_value_invalid - end - end - - context "and is provided" do - it "returns true if mortgage, grant and deposit total does not equal market value - discount" do - record.mortgage = 10 - expect(record).to be_discounted_ownership_value_invalid - end - - it "returns false if mortgage, grant and deposit total equals market value - discount" do - record.mortgage = 10_000 - expect(record).not_to be_discounted_ownership_value_invalid - end - end - end - - context "when mortgage is not routed to" do - let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, deposit: 5_000, grant: 3_000, value: 20_000, discount: 10, ownershipsch: 2, saledate: Time.zone.local(2023, 4, 3)) } - - it "returns true if grant and deposit total does not equal market value - discount" do - expect(record).to be_discounted_ownership_value_invalid - end - - it "returns false if mortgage, grant and deposit total equals market value - discount" do - record.grant = 13_000 - expect(record).not_to be_discounted_ownership_value_invalid - end - end - - context "when ownership is not discounted" do - let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, deposit: 5_000, grant: 3_000, value: 20_000, discount: 10, ownershipsch: 1, saledate: Time.zone.local(2023, 4, 3)) } - - it "returns false" do - expect(record).not_to be_discounted_ownership_value_invalid - end - end - - context "when it is a 2024 log" do - let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, deposit: 5_000, grant: 3_000, value: 20_000, discount: 10, ownershipsch: 2, saledate: Time.zone.local(2024, 4, 3)) } - - it "returns true if mortgage, grant and deposit total does not equal market value - discount" do - record.mortgage = 10 - expect(record).not_to be_discounted_ownership_value_invalid - end - end - end describe "#buyer1_livein_wrong_for_ownership_type?" do context "when it's a shared ownership" do