Browse Source

Update soft validation content

pull/1429/head
Kat 3 years ago
parent
commit
28683046a7
  1. 9
      app/models/form/sales/pages/discounted_sale_value_check.rb
  2. 2
      app/models/form/sales/questions/discounted_sale_value_check.rb
  3. 15
      app/models/sales_log.rb
  4. 8
      app/models/validations/sales/sale_information_validations.rb
  5. 7
      app/models/validations/sales/soft_validations.rb
  6. 3
      config/locales/en.yml
  7. 14
      spec/models/form/sales/pages/discounted_sale_value_check_spec.rb
  8. 2
      spec/models/form/sales/questions/discounted_sale_value_check_spec.rb
  9. 2
      spec/models/sales_log_spec.rb

9
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 = [
{

2
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" },

15
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

8
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

7
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

3
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:

14
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

2
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

2
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

Loading…
Cancel
Save