Browse Source

CLDC-3571 Update outright sale financial validations (#2549)

* Update outright sale validation message

* Add outright sale guidance

* Update duplicate page id

* User guidance helper
pull/2546/head
kosiakkatrina 2 years ago
parent
commit
76cff4c39b
  1. 1
      app/models/form/sales/questions/deposit_amount.rb
  2. 1
      app/models/form/sales/questions/mortgage_amount.rb
  3. 7
      app/models/form/sales/questions/purchase_price.rb
  4. 4
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  5. 12
      app/models/validations/sales/sale_information_validations.rb
  6. 8
      app/views/form/guidance/_financial_calculations_outright_sale.html.erb
  7. 2
      config/locales/en.yml
  8. 2
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  9. 10
      spec/models/validations/sales/sale_information_validations_spec.rb

1
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

1
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

7
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

4
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),

12
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

8
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 %>
<p class="govuk-body">
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) %>
</p>
<% end %>

2
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}.</br></br>The full purchase price%{discount_sentence} is %{value_with_discount}.</br></br>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}.</br></br>The full purchase price is %{value}.</br></br>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:

2
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

10
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.</br></br>The full purchase price is £300,000.00.</br></br>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.</br></br>The full purchase price is £300,000.00.</br></br>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.</br></br>The full purchase price is £300,000.00.</br></br>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.</br></br>The full purchase price is £300,000.00.</br></br>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.</br></br>The full purchase price is £300,000.00.</br></br>These two amounts should be the same.")
end
end

Loading…
Cancel
Save