Browse Source

CLDC-4168: Make mortgage length conditional on interview

requires a little changing to question logic to account for if the conditional question is not visible right now
pull/3195/head
samyou-softwire 3 weeks ago
parent
commit
fda27bdb73
  1. 5
      app/models/form/question.rb
  2. 3
      app/models/form/sales/pages/mortgage_length.rb
  3. 16
      app/models/form/sales/pages/mortgage_length_interviewed.rb
  4. 15
      app/models/form/sales/pages/mortgage_length_not_interviewed.rb
  5. 4
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  6. 4
      app/models/form/sales/subsections/outright_sale.rb
  7. 4
      app/models/form/sales/subsections/shared_ownership_initial_purchase.rb

5
app/models/form/question.rb

@ -340,7 +340,10 @@ private
end
def evaluate_condition(condition, log)
case page.questions.find { |q| q.id == condition[:from] }.type
conditional_question = page.questions.find { |q| q.id == condition[:from] }
return true unless conditional_question
case conditional_question.type
when "numeric"
operator = condition[:cond][/[<>=]+/].to_sym
operand = condition[:cond][/\d+/].to_i

3
app/models/form/sales/pages/mortgage_length.rb

@ -9,8 +9,7 @@ class Form::Sales::Pages::MortgageLength < ::Form::Page
def questions
@questions ||= [
(Form::Sales::Questions::MortgageLengthKnown.new(nil, nil, self, ownershipsch: @ownershipsch) if form.start_year_2026_or_later?),
Form::Sales::Questions::MortgageLength.new(nil, nil, self, ownershipsch: @ownershipsch),
].compact
]
end
end

16
app/models/form/sales/pages/mortgage_length_interviewed.rb

@ -0,0 +1,16 @@
class Form::Sales::Pages::MortgageLengthInterviewed < ::Form::Page
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@ownershipsch = ownershipsch
@depends_on = [{
"mortgageused" => 1, "buyer_not_interviewed?" => false
}]
end
def questions
@questions ||= [
Form::Sales::Questions::MortgageLengthKnown.new(nil, nil, self, ownershipsch: @ownershipsch),
Form::Sales::Questions::MortgageLength.new(nil, nil, self, ownershipsch: @ownershipsch),
]
end
end

15
app/models/form/sales/pages/mortgage_length_not_interviewed.rb

@ -0,0 +1,15 @@
class Form::Sales::Pages::MortgageLengthNotInterviewed < ::Form::Page
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@ownershipsch = ownershipsch
@depends_on = [
{ "mortgageused" => 1, "buyer_not_interviewed?" => true },
]
end
def questions
@questions ||= [
Form::Sales::Questions::MortgageLength.new(nil, nil, self, ownershipsch: @ownershipsch),
]
end
end

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

@ -30,7 +30,9 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_mortgage_value_check", nil, self),
Form::Sales::Pages::DepositAndMortgageValueCheck.new("discounted_ownership_deposit_and_mortgage_value_check_after_mortgage", nil, self),
mortgage_lender_questions,
Form::Sales::Pages::MortgageLength.new("mortgage_length_discounted_ownership", nil, self, ownershipsch: 2),
(Form::Sales::Pages::MortgageLength.new("mortgage_length_discounted_ownership", nil, self, ownershipsch: 2) unless form.start_year_2026_or_later?),
(Form::Sales::Pages::MortgageLengthNotInterviewed.new("mortgage_length_discounted_ownership_not_interviewed", nil, self, ownershipsch: 2) if form.start_year_2026_or_later?),
(Form::Sales::Pages::MortgageLengthInterviewed.new("mortgage_length_discounted_ownership_interviewed", nil, self, ownershipsch: 2) if form.start_year_2026_or_later?),
Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_discounted_ownership", nil, self, ownershipsch: 2),
Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_value_check", nil, self),
Form::Sales::Pages::Deposit.new("deposit_discounted_ownership", nil, self, ownershipsch: 2, optional: false),

4
app/models/form/sales/subsections/outright_sale.rb

@ -17,7 +17,9 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection
Form::Sales::Pages::MortgageValueCheck.new("outright_sale_mortgage_amount_mortgage_value_check", nil, self),
(Form::Sales::Pages::MortgageLender.new("mortgage_lender_outright_sale", nil, self, ownershipsch: 3) unless form.start_year_2024_or_later?),
(Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_outright_sale", nil, self, ownershipsch: 3) unless form.start_year_2024_or_later?),
Form::Sales::Pages::MortgageLength.new("mortgage_length_outright_sale", nil, self, ownershipsch: 3),
(Form::Sales::Pages::MortgageLength.new("mortgage_length_outright_sale", nil, self, ownershipsch: 3) unless form.start_year_2026_or_later?),
(Form::Sales::Pages::MortgageLengthNotInterviewed.new("mortgage_length_outright_sale_not_interviewed", nil, self, ownershipsch: 3) if form.start_year_2026_or_later?),
(Form::Sales::Pages::MortgageLengthInterviewed.new("mortgage_length_outright_sale_interviewed", nil, self, ownershipsch: 3) if form.start_year_2026_or_later?),
Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_outright_sale", nil, self, ownershipsch: 3),
Form::Sales::Pages::Deposit.new("deposit_outright_sale", nil, self, ownershipsch: 3, optional: false),
Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_joint_purchase_value_check", nil, self, joint_purchase: true),

4
app/models/form/sales/subsections/shared_ownership_initial_purchase.rb

@ -28,7 +28,9 @@ class Form::Sales::Subsections::SharedOwnershipInitialPurchase < ::Form::Subsect
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self, ownershipsch: 1),
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_mortgage_amount_value_check", nil, self),
Form::Sales::Pages::MortgageValueCheck.new("mortgage_amount_mortgage_value_check", nil, self),
Form::Sales::Pages::MortgageLength.new("mortgage_length_shared_ownership", nil, self, ownershipsch: 1),
(Form::Sales::Pages::MortgageLength.new("mortgage_length_shared_ownership", nil, self, ownershipsch: 1) unless form.start_year_2026_or_later?),
(Form::Sales::Pages::MortgageLengthNotInterviewed.new("mortgage_length_shared_ownership_not_interviewed", nil, self, ownershipsch: 1) if form.start_year_2026_or_later?),
(Form::Sales::Pages::MortgageLengthInterviewed.new("mortgage_length_shared_ownership_interviewed", nil, self, ownershipsch: 1) if form.start_year_2026_or_later?),
Form::Sales::Pages::Deposit.new("deposit_shared_ownership", nil, self, ownershipsch: 1, optional: false),
Form::Sales::Pages::Deposit.new("deposit_shared_ownership_optional", nil, self, ownershipsch: 1, optional: true),
Form::Sales::Pages::DepositValueCheck.new("deposit_joint_purchase_value_check", nil, self, joint_purchase: true),

Loading…
Cancel
Save