From c5bb9c6eaf8638355591455bf5d183fbb9f07d03 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Tue, 24 Jan 2023 18:15:43 +0000 Subject: [PATCH] feat: add min and max conditional text --- ..._price_shared_ownership_max_value_check.rb | 38 +++++++++++++++++++ ..._price_shared_ownership_min_value_check.rb | 38 +++++++++++++++++++ ...bout_price_shared_ownership_value_check.rb | 18 --------- .../form/sales/pages/handover_date_check.rb | 2 +- ...bout_price_shared_ownership_value_check.rb | 4 +- .../subsections/shared_ownership_scheme.rb | 3 +- app/models/sales_log.rb | 8 ++++ .../validations/sales/soft_validations.rb | 11 +++++- config/locales/en.yml | 25 +++++++----- .../sales/pages/handover_date_check_spec.rb | 2 +- 10 files changed, 115 insertions(+), 34 deletions(-) create mode 100644 app/models/form/sales/pages/about_price_shared_ownership_max_value_check.rb create mode 100644 app/models/form/sales/pages/about_price_shared_ownership_min_value_check.rb delete mode 100644 app/models/form/sales/pages/about_price_shared_ownership_value_check.rb 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 new file mode 100644 index 000000000..1d8856273 --- /dev/null +++ b/app/models/form/sales/pages/about_price_shared_ownership_max_value_check.rb @@ -0,0 +1,38 @@ +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 new file mode 100644 index 000000000..82adb77a3 --- /dev/null +++ b/app/models/form/sales/pages/about_price_shared_ownership_min_value_check.rb @@ -0,0 +1,38 @@ +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 deleted file mode 100644 index 8cd3fffe8..000000000 --- a/app/models/form/sales/pages/about_price_shared_ownership_value_check.rb +++ /dev/null @@ -1,18 +0,0 @@ -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/pages/handover_date_check.rb b/app/models/form/sales/pages/handover_date_check.rb index cc0ce9a9b..12ab7c2e3 100644 --- a/app/models/form/sales/pages/handover_date_check.rb +++ b/app/models/form/sales/pages/handover_date_check.rb @@ -1,7 +1,7 @@ class Form::Sales::Pages::HandoverDateCheck < ::Form::Page def initialize(id, hsh, subsection) super - @depends_on = [{ "hodate_3_years_or_more_saledate?" => true }] + @depends_on = [{ "hodate_3_years_or_more_exdate?" => true }] @informative_text = {} 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 index 218f17c5e..0b2091ba7 100644 --- 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 @@ -2,8 +2,8 @@ class Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck < ::Form::Ques def initialize(id, hsh, page) super @id = "value_value_check" - @check_answer_label = "Deposit confirmation" - @header = "Are you sure? This purchase price is outside the expected range for this local authority and number of bedrooms" + @check_answer_label = "Purchase price confirmation" + @header = "Are you sure this is correct?" @type = "interruption_screen" @answer_options = { "0" => { "value" => "Yes" }, diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 02c38994b..e72ec996b 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -21,7 +21,8 @@ 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::AboutPriceSharedOwnershipMinValueCheck.new(nil, nil, self), + Form::Sales::Pages::AboutPriceSharedOwnershipMaxValueCheck.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/sales_log.rb b/app/models/sales_log.rb index 45bd9f729..e4fcf1168 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -202,4 +202,12 @@ class SalesLog < Log def old_persons_shared_ownership? type == 24 end + + def purchase_price_soft_min + LaPurchasePriceRange.find_by(start_year: collection_start_year, la:, bedrooms: beds).soft_min + end + + def purchase_price_soft_max + LaPurchasePriceRange.find_by(start_year: collection_start_year, la:, bedrooms: beds).soft_max + end end diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index d1f9a096a..d591576f8 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -43,10 +43,17 @@ module Validations::Sales::SoftValidations ((exdate.to_date - hodate.to_date).to_i / 365) >= 3 end - def purchase_price_out_of_expected_range? + def purchase_price_below_soft_min? return unless value && beds && la purchase_price_range = LaPurchasePriceRange.find_by(start_year: collection_start_year, la:, bedrooms: beds) - purchase_price_range.present? && !value.between?(purchase_price_range.soft_min, purchase_price_range.soft_max) + purchase_price_range.present? && value < purchase_price_range.soft_min + end + + def purchase_price_above_soft_max? + 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_max end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 68c7199de..520bcd506 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -301,7 +301,7 @@ en: child_over_20: "Answer cannot be 20 or over as the relationship is ‘child’" not_student_16_19: "Answer cannot be between 16 and 19 as person %{person_num} is a child of the lead tenant but is not a full-time student" student_16_19: - cannot_be_16_19: + cannot_be_16_19: student_not_child: "Person cannot be aged 16-19 if they are a student but don't have relationship ‘child’" child_not_student: "Person cannot be aged 16-19 if they have relationship ‘child’ but are not a student" must_be_16_19: "Person must be aged 16-19 if they are a student and have relationship ‘child’" @@ -313,8 +313,8 @@ en: child_under_16: "Person’s %{person_num} working situation must be ’child under 16‘ as you told us they’re under 16" child_over_16: "Answer cannot be ‘child under 16’ as you told us the person %{person_num} is older than 16" not_student_16_19: "Person’s %{person_num} working situation must be full-time student or prefers not to say as you told us they’re between 16 and 19." - student_16_19: - cannot_be_student: + student_16_19: + cannot_be_student: child_not_16_19: "Person cannot be a student if they are not aged 16-19 but have relationship ‘child’" 16_19_not_child: "Person cannot be a student if they are aged 16-19 but don‘t have relationship ‘child’" must_be_student: "Person must be a student if they are aged 16-19 and have relationship ‘child’" @@ -326,8 +326,8 @@ en: child_over_20: "Answer cannot be ‘child’ if the person's age is 20 or over" one_partner: "Number of partners cannot be greater than 1" not_student_16_19: "Answer cannot be ‘child’ as you told us the person %{person_num} is between 16 and 19 and is not a full-time student" - student_16_19: - cannot_be_child: + student_16_19: + cannot_be_child: student_not_16_19: "Answer cannot be ‘child’ if the person is a student but not aged 16-19" 16_19_not_student: "Answer cannot be ‘child’ if the person is aged 16-19 but not a student" must_be_child: "Answer must be ‘child’ if the person is aged 16-19 and a student" @@ -413,9 +413,9 @@ en: deactivation: during_deactivated_period: "The location is already deactivated during this date, please enter a different date" sale_information: - previous_property_beds: + previous_property_beds: property_type_bedsit: "Bedsit bedroom maximum 1" - previous_property_type: + previous_property_type: property_type_bedsit: "A bedsit can not have more than 1 bedroom" soft_validations: @@ -429,10 +429,17 @@ en: rent: min: title_text: "You told us the rent is %{brent}" - hint_text: "The minimum rent expected for this type of property in this local authority is £%{soft_min_for_period}." + hint_text: "The minimum rent expected for this type of property in this local authority is £%{soft_min_for_period}" max: 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}." + 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}" retirement: min: title: "You told us this person is under %{age} and retired" diff --git a/spec/models/form/sales/pages/handover_date_check_spec.rb b/spec/models/form/sales/pages/handover_date_check_spec.rb index e7ad99c83..56f6ac4bd 100644 --- a/spec/models/form/sales/pages/handover_date_check_spec.rb +++ b/spec/models/form/sales/pages/handover_date_check_spec.rb @@ -26,7 +26,7 @@ RSpec.describe Form::Sales::Pages::HandoverDateCheck, type: :model do it "has correct depends_on" do expect(page.depends_on).to eq([ { - "hodate_3_years_or_more_saledate?" => true, + "hodate_3_years_or_more_exdate?" => true, }, ]) end