diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index d9e5b59b4..55787df78 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/config/locales/en.yml b/config/locales/en.yml index 6154df8fe..0c8ec1bf6 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/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