From 28683046a77a9bbdaf5c0e260809c024a5118f10 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 17 Mar 2023 12:26:43 +0000 Subject: [PATCH] Update soft validation content --- .../sales/pages/discounted_sale_value_check.rb | 9 ++++++++- .../questions/discounted_sale_value_check.rb | 2 +- app/models/sales_log.rb | 15 +++++++++++++++ .../sales/sale_information_validations.rb | 8 ++------ app/models/validations/sales/soft_validations.rb | 7 +------ config/locales/en.yml | 3 +++ .../pages/discounted_sale_value_check_spec.rb | 14 ++++++++++++++ .../questions/discounted_sale_value_check_spec.rb | 2 +- spec/models/sales_log_spec.rb | 2 ++ 9 files changed, 47 insertions(+), 15 deletions(-) diff --git a/app/models/form/sales/pages/discounted_sale_value_check.rb b/app/models/form/sales/pages/discounted_sale_value_check.rb index d9ef3df3e..666f714d9 100644 --- a/app/models/form/sales/pages/discounted_sale_value_check.rb +++ b/app/models/form/sales/pages/discounted_sale_value_check.rb @@ -2,7 +2,14 @@ class Form::Sales::Pages::DiscountedSaleValueCheck < ::Form::Page def initialize(id, hsh, subsection, person_index = nil) super(id, hsh, subsection) @depends_on = depends_on - @informative_text = {} + @title_text = { + "translation" => "soft_validations.discounted_sale_value.title_text", + "arguments" => [{ "key" => "value_with_discount", "label" => false, "i18n_template" => "value_with_discount" }], + } + @informative_text = { + "translation" => "soft_validations.discounted_sale_value.informative_text", + "arguments" => [{ "key" => "mortgage_deposit_and_grand_total", "label" => false, "i18n_template" => "mortgage_deposit_and_grand_total" }], + } @person_index = person_index @depends_on = [ { diff --git a/app/models/form/sales/questions/discounted_sale_value_check.rb b/app/models/form/sales/questions/discounted_sale_value_check.rb index 712df40f0..1d86b2f32 100644 --- a/app/models/form/sales/questions/discounted_sale_value_check.rb +++ b/app/models/form/sales/questions/discounted_sale_value_check.rb @@ -3,7 +3,7 @@ class Form::Sales::Questions::DiscountedSaleValueCheck < ::Form::Question super @id = "discounted_sale_value_check" @check_answer_label = "Discounted sale value confirmation" - @header = "Are you sure?" + @header = "Are you sure this is correct?" @type = "interruption_screen" @answer_options = { "0" => { "value" => "Yes" }, diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 46a8a177e..972704c12 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -330,4 +330,19 @@ class SalesLog < Log def should_process_uprn_change? uprn_changed? && saledate && saledate.year >= 2023 end + + def value_with_discount + return if value.blank? + + discount_amount = discount ? value * discount / 100 : 0 + (value - discount_amount) + end + + def mortgage_deposit_and_grand_total + return if deposit.blank? + + grant_amount = grant || 0 + mortgage_amount = mortgage || 0 + mortgage_amount + deposit + grant_amount + end end diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index ae8d10dcf..7a0d3c824 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -52,13 +52,9 @@ module Validations::Sales::SaleInformationValidations return unless record.mortgage || record.mortgageused == 2 return unless record.discount || record.grant || record.type == 29 - discount_amount = record.discount ? record.value * record.discount / 100 : 0 - grant_amount = record.grant || 0 - mortgage_amount = record.mortgage || 0 - value_with_discount = (record.value - discount_amount) - if mortgage_amount + record.deposit + grant_amount != value_with_discount && record.discounted_ownership_sale? + if record.mortgage_deposit_and_grand_total != record.value_with_discount && record.discounted_ownership_sale? %i[mortgage deposit grant value discount ownershipsch].each do |field| - record.errors.add field, I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: sprintf("%.2f", value_with_discount)) + record.errors.add field, I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: sprintf("%.2f", record.value_with_discount)) end end end diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index f7db3f82e..bcae563fc 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -120,12 +120,7 @@ module Validations::Sales::SoftValidations return unless mortgage || mortgageused == 2 return unless discount || grant || type == 29 - discount_amount = discount ? value * discount / 100 : 0 - grant_amount = grant || 0 - mortgage_amount = mortgage || 0 - value_with_discount = (value - discount_amount) - - mortgage_amount + deposit + grant_amount != value_with_discount && discounted_ownership_sale? + mortgage_deposit_and_grand_total != value_with_discount && discounted_ownership_sale? end private diff --git a/config/locales/en.yml b/config/locales/en.yml index 8c9cd12c1..5606d0980 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -525,6 +525,9 @@ en: title_text: "The amount of monthly charges is high for this type of property and sale type" student_not_child: title_text: "You told us this person is a student aged beween 16 and 19" + discounted_sale_value: + title_text: "Mortgage, deposit, and grant total must equal £%{value_with_discount}" + informative_text: "Your given mortgage, deposit and grand total is £%{mortgage_deposit_and_grand_total}" devise: two_factor_authentication: diff --git a/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb b/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb index 21a3d6080..ffa3b0408 100644 --- a/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb +++ b/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb @@ -24,6 +24,20 @@ RSpec.describe Form::Sales::Pages::DiscountedSaleValueCheck, type: :model do expect(page.header).to be_nil end + it "has the correct title_text" do + expect(page.title_text).to eq({ + "translation" => "soft_validations.discounted_sale_value.title_text", + "arguments" => [{ "key" => "value_with_discount", "label" => false, "i18n_template" => "value_with_discount" }], + }) + end + + it "has the correct informative_text" do + expect(page.informative_text).to eq({ + "translation" => "soft_validations.discounted_sale_value.informative_text", + "arguments" => [{ "key" => "mortgage_deposit_and_grand_total", "label" => false, "i18n_template" => "mortgage_deposit_and_grand_total" }], + }) + end + it "is interruption screen page" do expect(page.interruption_screen?).to eq(true) end diff --git a/spec/models/form/sales/questions/discounted_sale_value_check_spec.rb b/spec/models/form/sales/questions/discounted_sale_value_check_spec.rb index aac2db5b5..8e9e4e7a7 100644 --- a/spec/models/form/sales/questions/discounted_sale_value_check_spec.rb +++ b/spec/models/form/sales/questions/discounted_sale_value_check_spec.rb @@ -16,7 +16,7 @@ RSpec.describe Form::Sales::Questions::DiscountedSaleValueCheck, type: :model do end it "has the correct header" do - expect(question.header).to eq("Are you sure?") + expect(question.header).to eq("Are you sure this is correct?") end it "has the correct check_answer_label" do diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index 890fa069f..d8f4ca5bc 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -61,6 +61,7 @@ RSpec.describe SalesLog, type: :model do old_persons_shared_ownership_value_check mortgagelender othtype + discounted_sale_value_check proplen mortlen frombeds @@ -79,6 +80,7 @@ RSpec.describe SalesLog, type: :model do old_persons_shared_ownership_value_check mortgagelender othtype + discounted_sale_value_check address_line2 county postcode_full