Browse Source

Update discounted sale guidance and errors

pull/2552/head
Kat 2 years ago
parent
commit
f73e5ee1e7
  1. 10
      app/models/validations/sales/sale_information_validations.rb
  2. 16
      app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb
  3. 42
      spec/models/validations/sales/sale_information_validations_spec.rb

10
app/models/validations/sales/sale_information_validations.rb

@ -51,18 +51,14 @@ module Validations::Sales::SaleInformationValidations
tolerance = record.discount ? record.value * 0.05 / 100 : 1
if over_tolerance?(record.mortgage_deposit_and_grant_total, record.value_with_discount, tolerance, strict: !record.discount.nil?) && record.discounted_ownership_sale?
deposit_and_grant_sentence = if record.grant.present?
", cash deposit (#{record.field_formatted_as_currency('deposit')}), and grant (#{record.field_formatted_as_currency('grant')})"
else
" and cash deposit (#{record.field_formatted_as_currency('deposit')})"
end
deposit_and_grant_sentence = record.grant.present? ? ", cash deposit (#{record.field_formatted_as_currency('deposit')}), and grant (#{record.field_formatted_as_currency('grant')})" : " and cash deposit (#{record.field_formatted_as_currency('deposit')})"
discount_sentence = record.discount.present? ? " (#{record.field_formatted_as_currency('value')}) subtracted by the sum of the full purchase price (#{record.field_formatted_as_currency('value')}) multiplied by the percentage discount (#{record.discount}%)" : ""
%i[mortgageused mortgage value deposit ownershipsch discount grant].each do |field|
record.errors.add field, I18n.t("validations.sale_information.discounted_ownership_value",
mortgage: record.mortgage&.positive? ? " (#{record.field_formatted_as_currency('mortgage')})" : "",
deposit_and_grant_sentence:,
mortgage_deposit_and_grant_total: record.field_formatted_as_currency("mortgage_deposit_and_grant_total"),
discount_sentence: record.discount.present? ? " (#{record.field_formatted_as_currency('value')}) times by the discount (#{record.discount}%)" : "",
discount_sentence:,
value_with_discount: record.field_formatted_as_currency("value_with_discount")).html_safe
end
end

16
app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb

@ -1,10 +1,20 @@
<% discount_question_link = question_link("discount", log, current_user)%>
<% grant_question_link = question_link("grant", log, current_user)%>
<% value_question_link = question_link("value", log, current_user) %>
<%= govuk_details(summary_text: "How the financial values are calculated") do %>
<p class="govuk-body">
The mortgage amount <%= question_link("mortgage", log, current_user) %>
<% if grant_question_link.blank? %>
and cash deposit <%= question_link("deposit", log, current_user) %>
<% else %>
cash deposit <%= question_link("deposit", log, current_user) %>
and grant <%= question_link("grant", log, current_user) %>
and grant <%= grant_question_link %>
<% end %>
added together must equal
the purchase price <%= question_link("value", log, current_user) %>
multiplied by the discount stake <%= question_link("discount", log, current_user) %>
the purchase price <%= value_question_link %>
<% if discount_question_link.present? %>
subtracted by the sum of the purchase price <%= value_question_link %>
multiplied by the discount <%= discount_question_link %>
<% end %>
</p>
<% end %>

42
spec/models/validations/sales/sale_information_validations_spec.rb

@ -345,13 +345,13 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
sale_information_validator.validate_discounted_ownership_value(record)
expect(record.errors["mortgageused"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
expect(record.errors["mortgage"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
expect(record.errors["value"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
expect(record.errors["deposit"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
expect(record.errors["ownershipsch"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
expect(record.errors["discount"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
expect(record.errors["grant"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
expect(record.errors["mortgageused"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
expect(record.errors["mortgage"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
expect(record.errors["value"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
expect(record.errors["deposit"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
expect(record.errors["ownershipsch"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
expect(record.errors["discount"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
expect(record.errors["grant"]).to include("The mortgage (£66,113.00) and cash deposit (£0.00) added together is £66,113.00.</br></br>The full purchase price (£123,000.00) subtracted by the sum of the full purchase price (£123,000.00) multiplied by the percentage discount (46.3%) is £66,051.00.</br></br>These two amounts should be the same.")
end
it "does not add errors if mortgage and deposit total is exactly 0.05% x market value away from market value - discount" do
@ -426,13 +426,13 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
it "returns true if mortgage, grant and deposit total does not equal market value - discount" do
record.mortgage = 10
sale_information_validator.validate_discounted_ownership_value(record)
expect(record.errors["mortgageused"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["mortgage"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["value"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["deposit"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["ownershipsch"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["discount"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["grant"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["mortgageused"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["mortgage"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["value"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["deposit"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["ownershipsch"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["discount"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["grant"]).to include("The mortgage (£10.00), cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,010.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
end
it "returns false if mortgage, grant and deposit total equals market value - discount" do
@ -455,13 +455,13 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
it "returns true if grant and deposit total does not equal market value - discount" do
sale_information_validator.validate_discounted_ownership_value(record)
expect(record.errors["mortgageused"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["mortgage"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["value"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["deposit"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["ownershipsch"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["discount"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["grant"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["mortgageused"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["mortgage"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["value"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["deposit"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["ownershipsch"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["discount"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
expect(record.errors["grant"]).to include("The mortgage, cash deposit (£5,000.00), and grant (£3,000.00) added together is £8,000.00.</br></br>The full purchase price (£20,000.00) subtracted by the sum of the full purchase price (£20,000.00) multiplied by the percentage discount (10.0%) is £18,000.00.</br></br>These two amounts should be the same.")
end
it "returns false if mortgage, grant and deposit total equals market value - discount" do

Loading…
Cancel
Save