From f73e5ee1e7c209b241ef3630d20030c5b3d6c001 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 7 Aug 2024 11:09:09 +0100 Subject: [PATCH] Update discounted sale guidance and errors --- .../sales/sale_information_validations.rb | 10 ++--- ...calculations_discounted_ownership.html.erb | 16 +++++-- .../sale_information_validations_spec.rb | 42 +++++++++---------- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index 9cd0bdb39..648b2a0bc 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/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 diff --git a/app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb b/app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb index 39d3ec4d4..6af42a727 100644 --- a/app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb +++ b/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 %>

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 %>

<% end %> diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb index 8d29b9999..6cfa71d21 100644 --- a/spec/models/validations/sales/sale_information_validations_spec.rb +++ b/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.

The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.

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.

The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.

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.

The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.

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.

The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.

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.

The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.

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.

The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.

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.

The full purchase price (£123,000.00) times by the discount (46.3%) is £66,051.00.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

The full purchase price (£20,000.00) times by the discount (10.0%) is £18,000.00.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

These two amounts should be the same.") end it "returns false if mortgage, grant and deposit total equals market value - discount" do