Browse Source

Dynamically display discount in the error message (#2122)

pull/2145/head
kosiakkatrina 11 months ago committed by GitHub
parent
commit
ffe482cab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/form/sales/pages/shared_ownership_deposit_value_check.rb
  2. 8
      app/models/sales_log.rb
  3. 2
      config/locales/en.yml
  4. 5
      spec/models/form/sales/pages/shared_ownership_deposit_value_check_spec.rb

4
app/models/form/sales/pages/shared_ownership_deposit_value_check.rb

@ -10,6 +10,10 @@ class Form::Sales::Pages::SharedOwnershipDepositValueCheck < ::Form::Page
@title_text = { @title_text = {
"translation" => "soft_validations.shared_ownership_deposit.title_text", "translation" => "soft_validations.shared_ownership_deposit.title_text",
"arguments" => [ "arguments" => [
{
"key" => "mortgage_deposit_and_discount_error_fields",
"i18n_template" => "mortgage_deposit_and_discount_error_fields",
},
{ {
"key" => "field_formatted_as_currency", "key" => "field_formatted_as_currency",
"arguments_for_key" => "mortgage_deposit_and_discount_total", "arguments_for_key" => "mortgage_deposit_and_discount_total",

8
app/models/sales_log.rb

@ -272,6 +272,14 @@ class SalesLog < Log
mortgage_amount + deposit_amount + cashdis_amount mortgage_amount + deposit_amount + cashdis_amount
end end
def mortgage_deposit_and_discount_error_fields
[
"mortgage",
"deposit",
cashdis.present? ? "discount" : nil,
].compact.to_sentence
end
def mortgage_and_deposit_total def mortgage_and_deposit_total
return unless mortgage && deposit return unless mortgage && deposit

2
config/locales/en.yml

@ -657,7 +657,7 @@ Make sure these answers are correct."
title_text: "You told us that the property has been vacant for more than 2 years." title_text: "You told us that the property has been vacant for more than 2 years."
hint_text: "This is higher than we would expect." hint_text: "This is higher than we would expect."
shared_ownership_deposit: shared_ownership_deposit:
title_text: "You told us that the mortgage, deposit and discount add up to %{mortgage_deposit_and_discount_total}" title_text: "You told us that the %{mortgage_deposit_and_discount_error_fields} add up to %{mortgage_deposit_and_discount_total}"
old_persons_shared_ownership: old_persons_shared_ownership:
title_text: "You told us the buyer is using the Older Persons Shared Ownership scheme." title_text: "You told us the buyer is using the Older Persons Shared Ownership scheme."
hint_text: "At least one buyer must be aged 65 years and over to use this scheme." hint_text: "At least one buyer must be aged 65 years and over to use this scheme."

5
spec/models/form/sales/pages/shared_ownership_deposit_value_check_spec.rb

@ -34,7 +34,10 @@ RSpec.describe Form::Sales::Pages::SharedOwnershipDepositValueCheck, type: :mode
it "has the correct title_text" do it "has the correct title_text" do
expect(page.title_text).to eq({ expect(page.title_text).to eq({
"translation" => "soft_validations.shared_ownership_deposit.title_text", "translation" => "soft_validations.shared_ownership_deposit.title_text",
"arguments" => [{ "arguments_for_key" => "mortgage_deposit_and_discount_total", "i18n_template" => "mortgage_deposit_and_discount_total", "key" => "field_formatted_as_currency" }], "arguments" => [
{ "i18n_template" => "mortgage_deposit_and_discount_error_fields", "key" => "mortgage_deposit_and_discount_error_fields" },
{ "arguments_for_key" => "mortgage_deposit_and_discount_total", "i18n_template" => "mortgage_deposit_and_discount_total", "key" => "field_formatted_as_currency" },
],
}) })
end end

Loading…
Cancel
Save