diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index 24703890e..9cd0bdb39 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -51,11 +51,16 @@ 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 %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: record.field_formatted_as_currency("deposit"), - grant: record.grant.present? ? " (#{record.field_formatted_as_currency('grant')})" : "", + 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}%)" : "", value_with_discount: record.field_formatted_as_currency("value_with_discount")).html_safe diff --git a/config/locales/en.yml b/config/locales/en.yml index 1def54df7..dea8a2393 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -644,7 +644,7 @@ en: must_be_after_hodate: "Sale completion date must be after practical completion or handover date" 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." + discounted_ownership_value: "The mortgage%{mortgage}%{deposit_and_grant_sentence} 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%{mortgage} and cash 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" diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb index b12c85260..8d29b9999 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), cash deposit (£0.00), and grant 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), cash deposit (£0.00), and grant 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), cash deposit (£0.00), and grant 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), cash deposit (£0.00), and grant 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), cash deposit (£0.00), and grant 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), cash deposit (£0.00), and grant 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), cash deposit (£0.00), and grant 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) 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.") end it "does not add errors if mortgage and deposit total is exactly 0.05% x market value away from market value - discount" do @@ -380,13 +380,13 @@ RSpec.describe Validations::Sales::SaleInformationValidations do record.deposit = 2_000 sale_information_validator.validate_discounted_ownership_value(record) - expect(record.errors["mortgageused"]).to include("The mortgage (£10,000.00), cash deposit (£2,000.00), and grant added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") - expect(record.errors["mortgage"]).to include("The mortgage (£10,000.00), cash deposit (£2,000.00), and grant added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") - expect(record.errors["value"]).to include("The mortgage (£10,000.00), cash deposit (£2,000.00), and grant added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") - expect(record.errors["deposit"]).to include("The mortgage (£10,000.00), cash deposit (£2,000.00), and grant added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") - expect(record.errors["ownershipsch"]).to include("The mortgage (£10,000.00), cash deposit (£2,000.00), and grant added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") - expect(record.errors["discount"]).to include("The mortgage (£10,000.00), cash deposit (£2,000.00), and grant added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") - expect(record.errors["grant"]).to include("The mortgage (£10,000.00), cash deposit (£2,000.00), and grant added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") + expect(record.errors["mortgageused"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") + expect(record.errors["mortgage"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") + expect(record.errors["ownershipsch"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") + expect(record.errors["discount"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") + expect(record.errors["grant"]).to include("The mortgage (£10,000.00) and cash deposit (£2,000.00) added together is £12,000.00.

The full purchase price is £30,000.00.

These two amounts should be the same.") end it "returns false if mortgage and deposit total equals market value" do diff --git a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb index ccefbe4be..f77c60dbb 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -1370,7 +1370,7 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do it "only adds errors to the discounted ownership field" do parser.valid? expect(parser.errors[:field_103]).to be_empty - expect(parser.errors[:field_117]).to include("The mortgage, cash deposit (£100.00), and grant added together is £100.00.

The full purchase price (£100.00) times by the discount (10.0%) is £90.00.

These two amounts should be the same.") + expect(parser.errors[:field_117]).to include("The mortgage and cash deposit (£100.00) added together is £100.00.

The full purchase price (£100.00) times by the discount (10.0%) is £90.00.

These two amounts should be the same.") expect(parser.errors[:field_126]).to be_empty end end