From 5b038ab4ad94918c6b5ff151f718da32485381be Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 7 Aug 2024 12:29:36 +0100 Subject: [PATCH] CLDC-3571 Update outright sale financial validations (#2549) * Update outright sale validation message * Add outright sale guidance * Update duplicate page id * User guidance helper --- app/models/form/sales/questions/deposit_amount.rb | 1 + app/models/form/sales/questions/mortgage_amount.rb | 1 + app/models/form/sales/questions/purchase_price.rb | 7 ++++++- .../sales/subsections/shared_ownership_scheme.rb | 4 ++-- .../sales/sale_information_validations.rb | 12 ++++++++++-- .../_financial_calculations_outright_sale.html.erb | 8 ++++++++ config/locales/en.yml | 2 +- .../subsections/shared_ownership_scheme_spec.rb | 2 +- .../sales/sale_information_validations_spec.rb | 10 +++++----- 9 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 app/views/form/guidance/_financial_calculations_outright_sale.html.erb diff --git a/app/models/form/sales/questions/deposit_amount.rb b/app/models/form/sales/questions/deposit_amount.rb index e7e78b5c0..c1d91cc12 100644 --- a/app/models/form/sales/questions/deposit_amount.rb +++ b/app/models/form/sales/questions/deposit_amount.rb @@ -36,5 +36,6 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question def top_guidance_partial return "financial_calculations_shared_ownership" if @ownershipsch == 1 return "financial_calculations_discounted_ownership" if @ownershipsch == 2 + return "financial_calculations_outright_sale" if @ownershipsch == 3 end end diff --git a/app/models/form/sales/questions/mortgage_amount.rb b/app/models/form/sales/questions/mortgage_amount.rb index 446583921..cfd031f27 100644 --- a/app/models/form/sales/questions/mortgage_amount.rb +++ b/app/models/form/sales/questions/mortgage_amount.rb @@ -27,5 +27,6 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question def top_guidance_partial return "financial_calculations_shared_ownership" if @ownershipsch == 1 return "financial_calculations_discounted_ownership" if @ownershipsch == 2 + return "financial_calculations_outright_sale" if @ownershipsch == 3 end end diff --git a/app/models/form/sales/questions/purchase_price.rb b/app/models/form/sales/questions/purchase_price.rb index 68c9436d3..3a9bd4ee7 100644 --- a/app/models/form/sales/questions/purchase_price.rb +++ b/app/models/form/sales/questions/purchase_price.rb @@ -12,7 +12,7 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question @hint_text = hint_text @ownership_sch = ownershipsch @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] - @top_guidance_partial = "financial_calculations_discounted_ownership" if ownershipsch == 2 + @top_guidance_partial = top_guidance_partial end QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { @@ -25,4 +25,9 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question "For all schemes, including Right to Acquire (RTA), Right to Buy (RTB), Voluntary Right to Buy (VRTB) or Preserved Right to Buy (PRTB) sales, enter the full price of the property without any discount" end + + def top_guidance_partial + return "financial_calculations_discounted_ownership" if @ownership_sch == 2 + return "financial_calculations_outright_sale" if @ownership_sch == 3 + 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 371e125bb..c955929dc 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -43,8 +43,8 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection (Form::Sales::Pages::Deposit.new("deposit_shared_ownership_optional", nil, self, ownershipsch: 1, optional: true) if form.start_year_after_2024?), Form::Sales::Pages::DepositValueCheck.new("deposit_joint_purchase_value_check", nil, self, joint_purchase: true), Form::Sales::Pages::DepositValueCheck.new("deposit_value_check", nil, self, joint_purchase: false), - Form::Sales::Pages::DepositDiscount.new("discount", nil, self, optional: false), - (Form::Sales::Pages::DepositDiscount.new("discount_optional", nil, self, optional: true) if form.start_year_after_2024?), + Form::Sales::Pages::DepositDiscount.new("deposit_discount", nil, self, optional: false), + (Form::Sales::Pages::DepositDiscount.new("deposit_discount_optional", nil, self, optional: true) if form.start_year_after_2024?), Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_deposit_value_check", nil, self), Form::Sales::Pages::MonthlyRent.new(nil, nil, self), Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_shared_ownership", nil, self, ownershipsch: 1), diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index d9e5b59b4..24703890e 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -71,9 +71,17 @@ module Validations::Sales::SaleInformationValidations if over_tolerance?(record.mortgage_and_deposit_total, record.value, 1) %i[mortgageused mortgage value deposit].each do |field| - record.errors.add field, I18n.t("validations.sale_information.outright_sale_value", mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), value: record.field_formatted_as_currency("value")) + record.errors.add field, I18n.t("validations.sale_information.outright_sale_value", + mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), + mortgage: record.mortgage&.positive? ? " (#{record.field_formatted_as_currency('mortgage')})" : "", + deposit: record.field_formatted_as_currency("deposit"), + value: record.field_formatted_as_currency("value")).html_safe end - record.errors.add :ownershipsch, :skip_bu_error, message: I18n.t("validations.sale_information.outright_sale_value", mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), value: record.field_formatted_as_currency("value")) + record.errors.add :ownershipsch, :skip_bu_error, message: I18n.t("validations.sale_information.outright_sale_value", + mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), + mortgage: record.mortgage&.positive? ? " (#{record.field_formatted_as_currency('mortgage')})" : "", + deposit: record.field_formatted_as_currency("deposit"), + value: record.field_formatted_as_currency("value")).html_safe end end diff --git a/app/views/form/guidance/_financial_calculations_outright_sale.html.erb b/app/views/form/guidance/_financial_calculations_outright_sale.html.erb new file mode 100644 index 000000000..bd57bd63c --- /dev/null +++ b/app/views/form/guidance/_financial_calculations_outright_sale.html.erb @@ -0,0 +1,8 @@ +<%= govuk_details(summary_text: "How the financial values are calculated") do %> +
+ The mortgage amount <%= question_link("mortgage", log, current_user) %> + and cash deposit <%= question_link("deposit", log, current_user) %> + added together must equal + the purchase price <%= question_link("value", log, current_user) %> +
+<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index e45968e39..f4a0ee501 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -645,7 +645,7 @@ en: previous_property_type: property_type_bedsit: "A bedsit cannot have more than 1 bedroom" discounted_ownership_value: "The mortgage%{mortgage}, cash deposit (%{deposit}), and grant%{grant} added together is %{mortgage_deposit_and_grant_total}.The full purchase price%{discount_sentence} is %{value_with_discount}.These two amounts should be the same." - outright_sale_value: "The mortgage and deposit when added together is %{mortgage_and_deposit_total}, and the purchase price is %{value}. These figures should be the same." + outright_sale_value: "The mortgage%{mortgage} and deposit (%{deposit}) when added together is %{mortgage_and_deposit_total}.The full purchase price is %{value}.These two amounts should be the same." monthly_rent: higher_than_expected: "Basic monthly rent must be between £0.00 and £9,999.00" grant: diff --git a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb index e28fad3cc..ea3fcd40e 100644 --- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb @@ -52,7 +52,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do deposit_shared_ownership deposit_joint_purchase_value_check deposit_value_check - discount + deposit_discount shared_ownership_deposit_value_check monthly_rent leasehold_charges_shared_ownership diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb index 1c4ded586..7a03f64aa 100644 --- a/spec/models/validations/sales/sale_information_validations_spec.rb +++ b/spec/models/validations/sales/sale_information_validations_spec.rb @@ -538,11 +538,11 @@ RSpec.describe Validations::Sales::SaleInformationValidations do it "adds errors" do sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record) - expect(record.errors["mortgageused"]).to include("The mortgage and deposit when added together is £200,000.00, and the purchase price is £300,000.00. These figures should be the same.") - expect(record.errors["mortgage"]).to include("The mortgage and deposit when added together is £200,000.00, and the purchase price is £300,000.00. These figures should be the same.") - expect(record.errors["deposit"]).to include("The mortgage and deposit when added together is £200,000.00, and the purchase price is £300,000.00. These figures should be the same.") - expect(record.errors["value"]).to include("The mortgage and deposit when added together is £200,000.00, and the purchase price is £300,000.00. These figures should be the same.") - expect(record.errors["ownershipsch"]).to include("The mortgage and deposit when added together is £200,000.00, and the purchase price is £300,000.00. These figures should be the same.") + expect(record.errors["mortgageused"]).to include("The mortgage (£100,000.00) and deposit (£100,000.00) when added together is £200,000.00.The full purchase price is £300,000.00.These two amounts should be the same.") + expect(record.errors["mortgage"]).to include("The mortgage (£100,000.00) and deposit (£100,000.00) when added together is £200,000.00.The full purchase price is £300,000.00.These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage (£100,000.00) and deposit (£100,000.00) when added together is £200,000.00.The full purchase price is £300,000.00.These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage (£100,000.00) and deposit (£100,000.00) when added together is £200,000.00.The full purchase price is £300,000.00.These two amounts should be the same.") + expect(record.errors["ownershipsch"]).to include("The mortgage (£100,000.00) and deposit (£100,000.00) when added together is £200,000.00.The full purchase price is £300,000.00.These two amounts should be the same.") end end