Browse Source

implement soft validation of grant value

pull/1220/head
Arthur Campbell 3 years ago
parent
commit
17df96015f
  1. 18
      app/models/form/sales/pages/grant_value_check.rb
  2. 23
      app/models/form/sales/questions/grant_value_check.rb
  3. 1
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  4. 6
      app/models/validations/sales/soft_validations.rb

18
app/models/form/sales/pages/grant_value_check.rb

@ -0,0 +1,18 @@
class Form::Sales::Pages::GrantValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "grant_value_check"
@depends_on = [
{
"grant_outside_common_range?" => true,
},
]
@informative_text = {}
end
def questions
@questions ||= [
Form::Sales::Questions::GrantValueCheck.new(nil, nil, self),
]
end
end

23
app/models/form/sales/questions/grant_value_check.rb

@ -0,0 +1,23 @@
class Form::Sales::Questions::GrantValueCheck < ::Form::Question
def initialize(id, hsh, page)
super
@id = "grant_value_check"
@check_answer_label = "Grant value confirmation"
@header = "Are you sure? Grants are usually £9,000 - £16,000"
@type = "interruption_screen"
@answer_options = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}
@hidden_in_check_answers = {
"depends_on" => [
{
"grant_value_check" => 0,
},
{
"grant_value_check" => 1,
},
],
}
end
end

1
app/models/form/sales/subsections/discounted_ownership_scheme.rb

@ -11,6 +11,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_discounted_ownership", nil, self), Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_discounted_ownership", nil, self),
Form::Sales::Pages::AboutPriceRtb.new(nil, nil, self), Form::Sales::Pages::AboutPriceRtb.new(nil, nil, self),
Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self), Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self),
Form::Sales::Pages::GrantValueCheck.new(nil, nil, self),
Form::Sales::Pages::PurchasePrice.new("purchase_price_discounted_ownership", nil, self), Form::Sales::Pages::PurchasePrice.new("purchase_price_discounted_ownership", nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self),

6
app/models/validations/sales/soft_validations.rb

@ -42,4 +42,10 @@ module Validations::Sales::SoftValidations
((saledate.to_date - hodate.to_date).to_i / 365) >= 3 ((saledate.to_date - hodate.to_date).to_i / 365) >= 3
end end
def grant_outside_common_range?
return unless grant
!(9_000..16_000).cover? grant
end
end end

Loading…
Cancel
Save