diff --git a/app/models/form/sales/pages/about_price_shared_ownership_max_value_check.rb b/app/models/form/sales/pages/about_price_shared_ownership_max_value_check.rb deleted file mode 100644 index 1d8856273..000000000 --- a/app/models/form/sales/pages/about_price_shared_ownership_max_value_check.rb +++ /dev/null @@ -1,38 +0,0 @@ -class Form::Sales::Pages::AboutPriceSharedOwnershipMaxValueCheck < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "about_price_shared_ownership_max_value_check" - @depends_on = [ - { - "purchase_price_above_soft_max?" => true, - }, - ] - @informative_text = {} - @title_text = { - "translation" => "soft_validations.purchase_price.max.title_text", - "arguments" => [ - { - "key" => "value", - "label" => true, - "i18n_template" => "value", - }, - ], - } - @informative_text = { - "translation" => "soft_validations.purchase_price.max.hint_text", - "arguments" => [ - { - "key" => "purchase_price_soft_max", - "label" => false, - "i18n_template" => "soft_max", - }, - ], - } - end - - def questions - @questions ||= [ - Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck.new(nil, nil, self), - ] - end -end diff --git a/app/models/form/sales/pages/about_price_shared_ownership_min_value_check.rb b/app/models/form/sales/pages/about_price_shared_ownership_min_value_check.rb deleted file mode 100644 index 82adb77a3..000000000 --- a/app/models/form/sales/pages/about_price_shared_ownership_min_value_check.rb +++ /dev/null @@ -1,38 +0,0 @@ -class Form::Sales::Pages::AboutPriceSharedOwnershipMinValueCheck < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "about_price_shared_ownership_min_value_check" - @depends_on = [ - { - "purchase_price_below_soft_min?" => true, - }, - ] - @informative_text = {} - @title_text = { - "translation" => "soft_validations.purchase_price.min.title_text", - "arguments" => [ - { - "key" => "value", - "label" => true, - "i18n_template" => "value", - }, - ], - } - @informative_text = { - "translation" => "soft_validations.purchase_price.min.hint_text", - "arguments" => [ - { - "key" => "purchase_price_soft_min", - "label" => false, - "i18n_template" => "soft_min", - }, - ], - } - end - - def questions - @questions ||= [ - Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck.new(nil, nil, self), - ] - end -end 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..3fcefcea7 --- /dev/null +++ b/app/models/form/sales/pages/about_price_shared_ownership_value_check.rb @@ -0,0 +1,42 @@ +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_soft_range?" => true, + }, + ] + @title_text = { + "translation" => "soft_validations.purchase_price.title_text", + "arguments" => [ + { + "key" => "value", + "label" => true, + "i18n_template" => "value", + }, + ], + } + @informative_text = { + "translation" => "soft_validations.purchase_price.hint_text", + "arguments" => [ + { + "key" => "purchase_price_soft_min_or_soft_max", + "label" => false, + "i18n_template" => "soft_min_or_soft_max", + }, + { + "key" => "purchase_price_min_or_max_text", + "label" => false, + "i18n_template" => "min_or_max", + }, + ], + } + end + + def questions + @questions ||= [ + Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck.new(nil, nil, self), + ] + 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 e72ec996b..02c38994b 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -21,8 +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::AboutPriceSharedOwnershipMinValueCheck.new(nil, nil, self), - Form::Sales::Pages::AboutPriceSharedOwnershipMaxValueCheck.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 d591576f8..02c96e1f4 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -43,17 +43,25 @@ module Validations::Sales::SoftValidations ((exdate.to_date - hodate.to_date).to_i / 365) >= 3 end - def purchase_price_below_soft_min? + def purchase_price_out_of_soft_range? return unless value && beds && la - purchase_price_range = LaPurchasePriceRange.find_by(start_year: collection_start_year, la:, bedrooms: beds) - purchase_price_range.present? && value < purchase_price_range.soft_min + purchase_price_range.present? && !value.between?(purchase_price_range.soft_min, purchase_price_range.soft_max) end - def purchase_price_above_soft_max? - return unless value && beds && la + def purchase_price_min_or_max_text + + value < purchase_price_range.soft_min ? "minimum" : "maximum" + end + + def purchase_price_soft_min_or_soft_max + + value < purchase_price_range.soft_min ? purchase_price_range.soft_min : purchase_price_range.soft_max + end + +private - purchase_price_range = LaPurchasePriceRange.find_by(start_year: collection_start_year, la:, bedrooms: beds) - purchase_price_range.present? && value > purchase_price_range.soft_max + def purchase_price_range + LaPurchasePriceRange.find_by(start_year: collection_start_year, la:, bedrooms: beds) end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 520bcd506..fafde38b1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -434,12 +434,8 @@ en: title_text: "You told us the rent is %{brent}" hint_text: "The maximum rent expected for this type of property in this local authority is £%{soft_max_for_period}" purchase_price: - min: - title_text: "You told us the purchase price is %{value}" - hint_text: "The minimum purchase price expected for this type of property in this local authority is £%{soft_min}" - max: - title_text: "You told us the purchase price is %{value}" - hint_text: "The maximum purchase price expected for this type of property in this local authority is £%{soft_max}" + title_text: "You told us the purchase price is %{value}" + hint_text: "The %{min_or_max} purchase price expected for this type of property in this local authority is £%{soft_min_or_soft_max}" retirement: min: title: "You told us this person is under %{age} and retired" diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 965e79690..be9733321 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(184) 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(184) expect(form.name).to eq("2021_2022_sales") end end