diff --git a/app/models/form/question.rb b/app/models/form/question.rb index be90899f9..b3e7a36f7 100644 --- a/app/models/form/question.rb +++ b/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 diff --git a/app/models/form/sales/pages/mortgage_length.rb b/app/models/form/sales/pages/mortgage_length.rb index e80d68cff..dbc01a695 100644 --- a/app/models/form/sales/pages/mortgage_length.rb +++ b/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 diff --git a/app/models/form/sales/pages/mortgage_length_interviewed.rb b/app/models/form/sales/pages/mortgage_length_interviewed.rb new file mode 100644 index 000000000..4b378374f --- /dev/null +++ b/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 diff --git a/app/models/form/sales/pages/mortgage_length_not_interviewed.rb b/app/models/form/sales/pages/mortgage_length_not_interviewed.rb new file mode 100644 index 000000000..3e2dd7d9a --- /dev/null +++ b/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 diff --git a/app/models/form/sales/subsections/discounted_ownership_scheme.rb b/app/models/form/sales/subsections/discounted_ownership_scheme.rb index c74dcd262..dea8334b8 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/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), diff --git a/app/models/form/sales/subsections/outright_sale.rb b/app/models/form/sales/subsections/outright_sale.rb index afa0f4a69..5fbacdc6e 100644 --- a/app/models/form/sales/subsections/outright_sale.rb +++ b/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), diff --git a/app/models/form/sales/subsections/shared_ownership_initial_purchase.rb b/app/models/form/sales/subsections/shared_ownership_initial_purchase.rb index 4bfb10f2d..7ac9c0543 100644 --- a/app/models/form/sales/subsections/shared_ownership_initial_purchase.rb +++ b/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),