Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use automatic next node detection in existing flows (with feedback addressed) #2368

Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ccf2846
Add script to generate permitted next nodes for all flows
floehopper Mar 14, 2016
97dcf5d
Generate permitted next node YAML for all flows
floehopper Mar 14, 2016
1125b61
Automatic next_node detection in additional-commodity-code
floehopper Mar 10, 2016
ffc1c22
Automatic next_node detection in am-i-getting-minimum-wage
floehopper Mar 10, 2016
d7b26f0
Automatic next_node detection in benefit-cap-calculator
floehopper Mar 10, 2016
37747eb
Automatic next_node detection in calculate-agricultural-holiday-entit…
floehopper Mar 10, 2016
988036e
Automatic next_node detection in calculate-married-couples-allowance
floehopper Mar 10, 2016
b3c3992
Automatic next_node detection in calculate-statutory-sick-pay
floehopper Mar 10, 2016
42f3a5a
Automatic next_node detection in calculate-your-child-maintenance
floehopper Mar 10, 2016
fe10b84
Automatic next_node detection in calculate-your-holiday-entitlement
floehopper Mar 10, 2016
3fdb477
Automatic next_node detection in check-uk-visa
floehopper Mar 10, 2016
e677b48
Automatic next_node detection in childcare-costs-for-tax-credits
floehopper Mar 11, 2016
da49cac
Automatic next_node detection in energy-grants-calculator
floehopper Mar 11, 2016
a4b0dd4
Automatic next_node detection in estimate-self-assessment-penalties
floehopper Mar 14, 2016
0fec0b2
Automatic next_node detection in help-if-you-are-arrested-abroad
floehopper Mar 14, 2016
a89fa66
Automatic next_node detection in inherits-someone-dies-without-will
floehopper Mar 14, 2016
eb54fe0
Automatic next_node detection in landlord-immigration-check
floehopper Mar 14, 2016
06c84be
Automatic next_node detection in marriage-abroad
floehopper Mar 14, 2016
b47307f
Automatic next_node detection in maternity-paternity-calculator
floehopper Mar 14, 2016
d125568
Automatic next_node detection in minimum-wage-calculator-employers
floehopper Mar 14, 2016
1a93136
Automatic next_node detection in overseas-passports
floehopper Mar 14, 2016
c38c725
Automatic next_node detection in part-year-profit-tax-credits
floehopper Mar 14, 2016
0933182
Automatic next_node detection in pay-leave-for-parents
floehopper Mar 14, 2016
8cb3518
Automatic next_node detection in pip-checker
floehopper Mar 14, 2016
85a88f6
Automatic next_node detection in register-a-birth
floehopper Mar 14, 2016
61ae9e9
Automatic next_node detection in register-a-death
floehopper Mar 14, 2016
98c6299
Automatic next_node detection in report-a-lost-or-stolen-passport
floehopper Mar 14, 2016
943fdd3
Automatic next_node detection in simplified-expenses-checker
floehopper Mar 14, 2016
5bcaff8
Automatic next_node detection in state-pension-age
floehopper Mar 14, 2016
6299e70
Automatic next_node detection in state-pension-through-partner
floehopper Mar 14, 2016
498c4c2
Automatic next_node detection in state-pension-topup
floehopper Mar 14, 2016
580af6e
Automatic next_node detection in student-finance-calculator
floehopper Mar 14, 2016
f85f32d
Automatic next_node detection in student-finance-forms
floehopper Mar 14, 2016
4f03224
Automatic next_node detection in towing-rules
floehopper Mar 14, 2016
d8b0421
Automatic next_node detection in uk-benefits-abroad
floehopper Mar 14, 2016
e687864
Automatic next_node detection in vat-payment-deadlines
floehopper Mar 14, 2016
b95e8d8
Automatic next_node detection in adoption-calculator
floehopper Mar 14, 2016
80bc4d3
Automatic next_node detection in maternity-calculator
floehopper Mar 14, 2016
a1bf0bd
Automatic next_node detection in minimum_wage
floehopper Mar 14, 2016
6c4951e
Automatic next_node detection in paternity-calculator
floehopper Mar 14, 2016
b9c3837
Automatic next_node detection in redundancy_pay
floehopper Mar 14, 2016
bbb14d1
Remove permitted next node YAML - no longer needed
floehopper Mar 14, 2016
718794e
Remove script to generate permitted next nodes for all flows
floehopper Mar 14, 2016
e381356
Fix Lint/UnusedBlockArgument Rubocop violation
floehopper Mar 14, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 12 additions & 28 deletions lib/smart_answer_flows/additional-commodity-code.rb
Original file line number Diff line number Diff line change
@@ -21,23 +21,16 @@ def define
nil
end

permitted_next_nodes = [
:how_much_sucrose_1?,
:how_much_sucrose_2?,
:how_much_sucrose_3?,
:how_much_sucrose_4?
]

next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response.to_i
when 25
:how_much_sucrose_2?
question :how_much_sucrose_2?
when 50
:how_much_sucrose_3?
question :how_much_sucrose_3?
when 75
:how_much_sucrose_4?
question :how_much_sucrose_4?
else
:how_much_sucrose_1?
question :how_much_sucrose_1?
end
end
end
@@ -101,29 +94,20 @@ def define

save_input_as :milk_fat_weight

permitted_next_nodes = [
:commodity_code_result,
:how_much_milk_protein_ab?,
:how_much_milk_protein_c?,
:how_much_milk_protein_d?,
:how_much_milk_protein_ef?,
:how_much_milk_protein_gh?
]

next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response.to_i
when 0, 1
:how_much_milk_protein_ab?
question :how_much_milk_protein_ab?
when 3
:how_much_milk_protein_c?
question :how_much_milk_protein_c?
when 6
:how_much_milk_protein_d?
question :how_much_milk_protein_d?
when 9, 12
:how_much_milk_protein_ef?
question :how_much_milk_protein_ef?
when 18, 26
:how_much_milk_protein_gh?
question :how_much_milk_protein_gh?
else
:commodity_code_result
outcome :commodity_code_result
end
end
end
36 changes: 10 additions & 26 deletions lib/smart_answer_flows/am-i-getting-minimum-wage.rb
Original file line number Diff line number Diff line change
@@ -20,20 +20,14 @@ def define
nil
end

permitted_next_nodes = [
:are_you_an_apprentice?,
:will_you_be_a_first_year_apprentice?,
:past_payment_date?
]

next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'current_payment'
:are_you_an_apprentice?
question :are_you_an_apprentice?
when 'current_payment_april_2016'
:will_you_be_a_first_year_apprentice?
question :will_you_be_a_first_year_apprentice?
when 'past_payment'
:past_payment_date?
question :past_payment_date?
end
end
end
@@ -43,18 +37,13 @@ def define
option :yes
option :no

permitted_next_nodes = [
:does_not_apply_to_first_year_apprentices,
:how_old_are_you?
]

next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
calculator.is_apprentice = true
:does_not_apply_to_first_year_apprentices
outcome :does_not_apply_to_first_year_apprentices
when 'no'
:how_old_are_you? #Q3
question :how_old_are_you? #Q3
end
end
end
@@ -81,17 +70,12 @@ def define
end
end

permitted_next_nodes = [
:under_school_leaving_age,
:how_often_do_you_get_paid?
]

next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.age = response
if calculator.under_school_leaving_age?
:under_school_leaving_age
outcome :under_school_leaving_age
else
:how_often_do_you_get_paid?
question :how_often_do_you_get_paid?
end
end
end
44 changes: 12 additions & 32 deletions lib/smart_answer_flows/benefit-cap-calculator.rb
Original file line number Diff line number Diff line change
@@ -13,16 +13,11 @@ def define

save_input_as :housing_benefit

permitted_next_nodes = [
:working_tax_credit?,
:outcome_not_affected_no_housing_benefit
]

next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response == 'yes'
:working_tax_credit?
question :working_tax_credit?
else
:outcome_not_affected_no_housing_benefit
outcome :outcome_not_affected_no_housing_benefit
end
end
end
@@ -32,16 +27,11 @@ def define
option :yes
option :no

permitted_next_nodes = [
:outcome_not_affected_exemptions,
:receiving_exemption_benefits?
]

next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response == 'yes'
:outcome_not_affected_exemptions
outcome :outcome_not_affected_exemptions
else
:receiving_exemption_benefits?
question :receiving_exemption_benefits?
end
end
end
@@ -51,16 +41,11 @@ def define
option :yes
option :no

permitted_next_nodes = [
:outcome_not_affected_exemptions,
:receiving_non_exemption_benefits?
]

next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response == 'yes'
:outcome_not_affected_exemptions
outcome :outcome_not_affected_exemptions
else
:receiving_non_exemption_benefits?
question :receiving_non_exemption_benefits?
end
end
end
@@ -521,22 +506,17 @@ def define
sprintf("%.2f", benefit_cap)
end

permitted_next_nodes = [
:outcome_affected_greater_than_cap,
:outcome_not_affected_less_than_cap
]

next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response == 'single'
cap = 350
else
cap = 500
end

if total_benefits > cap
:outcome_affected_greater_than_cap
outcome :outcome_affected_greater_than_cap
else
:outcome_not_affected_less_than_cap
outcome :outcome_not_affected_less_than_cap
end
end
end
Original file line number Diff line number Diff line change
@@ -16,16 +16,12 @@ def define
nil
end

permitted_next_nodes = [
:how_many_days_per_week?,
:what_date_does_holiday_start?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'same-number-of-days'
:how_many_days_per_week?
question :how_many_days_per_week?
when 'different-number-of-days'
:what_date_does_holiday_start?
question :what_date_does_holiday_start?
end
end
end
@@ -77,16 +73,12 @@ def define
end
end

permitted_next_nodes = [
:done,
:how_many_weeks_at_current_employer?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'same-employer'
:done
outcome :done
when 'multiple-employers'
:how_many_weeks_at_current_employer?
question :how_many_weeks_at_current_employer?
end
end
end
60 changes: 18 additions & 42 deletions lib/smart_answer_flows/calculate-married-couples-allowance.rb
Original file line number Diff line number Diff line change
@@ -33,16 +33,12 @@ def define
Calculators::MarriedCouplesAllowanceCalculator.new(validate_income: false)
end

permitted_next_nodes = [
:did_you_marry_or_civil_partner_before_5_december_2005?,
:sorry
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
:did_you_marry_or_civil_partner_before_5_december_2005?
question :did_you_marry_or_civil_partner_before_5_december_2005?
when 'no'
:sorry
outcome :sorry
end
end
end
@@ -62,16 +58,12 @@ def define
end
end

permitted_next_nodes = [
:whats_the_husbands_date_of_birth?,
:whats_the_highest_earners_date_of_birth?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
:whats_the_husbands_date_of_birth?
question :whats_the_husbands_date_of_birth?
when 'no'
:whats_the_highest_earners_date_of_birth?
question :whats_the_highest_earners_date_of_birth?
end
end
end
@@ -97,16 +89,12 @@ def define

validate { |response| response > 0 }

permitted_next_nodes = [
:paying_into_a_pension?,
:husband_done
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
limit = (is_before_april_changes ? 26100.0 : 27000.0)
if response.to_f >= limit
:paying_into_a_pension?
question :paying_into_a_pension?
else
:husband_done
outcome :husband_done
end
end
end
@@ -116,16 +104,12 @@ def define

validate { |response| response > 0 }

permitted_next_nodes = [
:paying_into_a_pension?,
:highest_earner_done
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
limit = (is_before_april_changes ? 26100.0 : 27000.0)
if response.to_f >= limit
:paying_into_a_pension?
question :paying_into_a_pension?
else
:highest_earner_done
outcome :highest_earner_done
end
end
end
@@ -134,16 +118,12 @@ def define
option :yes
option :no

permitted_next_nodes = [
:how_much_expected_contributions_before_tax?,
:how_much_expected_gift_aided_donations?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
:how_much_expected_contributions_before_tax?
question :how_much_expected_contributions_before_tax?
when 'no'
:how_much_expected_gift_aided_donations?
question :how_much_expected_gift_aided_donations?
end
end
end
@@ -165,15 +145,11 @@ def define
calculator.calculate_adjusted_net_income(income.to_f, (gross_pension_contributions.to_f || 0), (net_pension_contributions.to_f || 0), response)
end

permitted_next_nodes = [
:husband_done,
:highest_earner_done
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if income_measure == "husband"
:husband_done
outcome :husband_done
else
:highest_earner_done
outcome :highest_earner_done
end
end
end
118 changes: 47 additions & 71 deletions lib/smart_answer_flows/calculate-statutory-sick-pay.rb
Original file line number Diff line number Diff line change
@@ -19,13 +19,12 @@ def define
Calculators::StatutorySickPayCalculator.new
end

permitted_next_nodes = [:employee_tell_within_limit?, :already_getting_maternity]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.other_pay_types_received = response.split(",")
if calculator.already_getting_maternity_pay?
:already_getting_maternity
outcome :already_getting_maternity
else
:employee_tell_within_limit?
question :employee_tell_within_limit?
end
end
end
@@ -35,13 +34,13 @@ def define
option :yes
option :no

next_node(permitted: [:employee_work_different_days?]) do |response|
next_node(permitted: :auto) do |response|
if response == 'yes'
calculator.enough_notice_of_absence = true
else
calculator.enough_notice_of_absence = false
end
:employee_work_different_days?
question :employee_work_different_days?
end
end

@@ -50,16 +49,12 @@ def define
option :yes
option :no

permitted_next_nodes = [
:not_regular_schedule,
:first_sick_day?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
:not_regular_schedule # Answer 4
outcome :not_regular_schedule # Answer 4
when 'no'
:first_sick_day? # Question 4
question :first_sick_day? # Question 4
end
end
end
@@ -70,9 +65,9 @@ def define
to { Date.today.end_of_year }
validate_in_range

next_node(permitted: [:last_sick_day?]) do |response|
next_node(permitted: :auto) do |response|
calculator.sick_start_date = response
:last_sick_day?
question :last_sick_day?
end
end

@@ -86,13 +81,12 @@ def define
calculator.valid_last_sick_day?(response)
end

permitted_next_nodes = [:has_linked_sickness?, :must_be_sick_for_4_days]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.sick_end_date = response
if calculator.valid_period_of_incapacity_for_work?
:has_linked_sickness?
question :has_linked_sickness?
else
:must_be_sick_for_4_days
outcome :must_be_sick_for_4_days
end
end
end
@@ -102,18 +96,14 @@ def define
option :yes
option :no

permitted_next_nodes = [
:linked_sickness_start_date?,
:paid_at_least_8_weeks?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
calculator.has_linked_sickness = true
:linked_sickness_start_date?
question :linked_sickness_start_date?
when 'no'
calculator.has_linked_sickness = false
:paid_at_least_8_weeks?
question :paid_at_least_8_weeks?
end
end
end
@@ -128,9 +118,9 @@ def define
calculator.valid_linked_sickness_start_date?(response)
end

next_node(permitted: [:linked_sickness_end_date?]) do |response|
next_node(permitted: :auto) do |response|
calculator.linked_sickness_start_date = response
:linked_sickness_end_date?
question :linked_sickness_end_date?
end
end

@@ -152,9 +142,9 @@ def define
calculator.valid_linked_period_of_incapacity_for_work?(response)
end

next_node(permitted: [:paid_at_least_8_weeks?]) do |response|
next_node(permitted: :auto) do |response|
calculator.linked_sickness_end_date = response
:paid_at_least_8_weeks?
question :paid_at_least_8_weeks?
end
end

@@ -168,18 +158,14 @@ def define
calculator.sick_start_date_for_awe
end

permitted_next_nodes = [
:how_often_pay_employee_pay_patterns?,
:total_earnings_before_sick_period?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.eight_weeks_earnings = response
if calculator.paid_at_least_8_weeks_of_earnings?
:how_often_pay_employee_pay_patterns? # Question 7.2
question :how_often_pay_employee_pay_patterns? # Question 7.2
elsif calculator.paid_less_than_8_weeks_of_earnings?
:total_earnings_before_sick_period? # Question 10
question :total_earnings_before_sick_period? # Question 10
elsif calculator.fell_sick_before_payday?
:how_often_pay_employee_pay_patterns? # Question 7.2
question :how_often_pay_employee_pay_patterns? # Question 7.2
end
end
end
@@ -192,16 +178,12 @@ def define
option :monthly
option :irregularly

permitted_next_nodes = [
:last_payday_before_sickness?,
:pay_amount_if_not_sick?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.pay_pattern = response
if calculator.paid_at_least_8_weeks_of_earnings?
:last_payday_before_sickness? # Question 8
question :last_payday_before_sickness? # Question 8
else
:pay_amount_if_not_sick? # Question 9
question :pay_amount_if_not_sick? # Question 9
end
end
end
@@ -220,9 +202,9 @@ def define
calculator.valid_last_payday_before_sickness?(response)
end

next_node(permitted: [:last_payday_before_offset?]) do |response|
next_node(permitted: :auto) do |response|
calculator.relevant_period_to = response
:last_payday_before_offset?
question :last_payday_before_offset?
end
end

@@ -240,9 +222,9 @@ def define
calculator.valid_last_payday_before_offset?(response)
end

next_node(permitted: [:total_employee_earnings?]) do |response|
next_node(permitted: :auto) do |response|
calculator.relevant_period_from = response + 1.day
:total_employee_earnings?
question :total_employee_earnings?
end
end

@@ -256,9 +238,9 @@ def define
calculator.relevant_period_to
end

next_node(permitted: [:usual_work_days?]) do |response|
next_node(permitted: :auto) do |response|
calculator.total_employee_earnings = response
:usual_work_days?
question :usual_work_days?
end
end

@@ -268,58 +250,52 @@ def define
calculator.sick_start_date_for_awe
end

next_node(permitted: [:contractual_days_covered_by_earnings?]) do |response|
next_node(permitted: :auto) do |response|
calculator.relevant_contractual_pay = response
:contractual_days_covered_by_earnings?
question :contractual_days_covered_by_earnings?
end
end

# Question 9.1
value_question :contractual_days_covered_by_earnings? do
next_node(permitted: [:usual_work_days?]) do |response|
next_node(permitted: :auto) do |response|
calculator.contractual_days_covered_by_earnings = response
:usual_work_days?
question :usual_work_days?
end
end

# Question 10
money_question :total_earnings_before_sick_period? do
next_node(permitted: [:days_covered_by_earnings?]) do |response|
next_node(permitted: :auto) do |response|
calculator.total_earnings_before_sick_period = response
:days_covered_by_earnings?
question :days_covered_by_earnings?
end
end

# Question 10.1
value_question :days_covered_by_earnings? do
next_node(permitted: [:usual_work_days?]) do |response|
next_node(permitted: :auto) do |response|
calculator.days_covered_by_earnings = response.to_i
:usual_work_days?
question :usual_work_days?
end
end

# Question 11
checkbox_question :usual_work_days? do
%w{1 2 3 4 5 6 0}.each { |n| option n.to_s }

permitted_next_nodes = [
:not_earned_enough,
:maximum_entitlement_reached,
:entitled_to_sick_pay,
:not_entitled_3_days_not_paid
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.days_of_the_week_worked = response.split(",")
if calculator.not_earned_enough?
:not_earned_enough
outcome :not_earned_enough
elsif calculator.maximum_entitlement_reached?
:maximum_entitlement_reached # Answer 8
outcome :maximum_entitlement_reached # Answer 8
elsif calculator.entitled_to_sick_pay?
:entitled_to_sick_pay # Answer 6
outcome :entitled_to_sick_pay # Answer 6
elsif calculator.maximum_entitlement_reached_v2?
:maximum_entitlement_reached # Answer 8
outcome :maximum_entitlement_reached # Answer 8
else
:not_entitled_3_days_not_paid # Answer 7
outcome :not_entitled_3_days_not_paid # Answer 7
end
end
end
36 changes: 11 additions & 25 deletions lib/smart_answer_flows/calculate-your-child-maintenance.rb
Original file line number Diff line number Diff line change
@@ -60,16 +60,12 @@ def define
Calculators::ChildMaintenanceCalculator.new(number_of_children, benefits, paying_or_receiving)
end

permitted_next_nodes = [
:how_many_nights_children_stay_with_payee?,
:gross_income_of_payee?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
:how_many_nights_children_stay_with_payee?
question :how_many_nights_children_stay_with_payee?
when 'no'
:gross_income_of_payee?
question :gross_income_of_payee?
end
end
end
@@ -90,19 +86,14 @@ def define
calculator.rate_type
end

permitted_next_nodes = [
:nil_rate_result,
:flat_rate_result,
:how_many_other_children_in_payees_household?
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
case rate_type
when :nil
:nil_rate_result
outcome :nil_rate_result
when :flat
:flat_rate_result
outcome :flat_rate_result
else
:how_many_other_children_in_payees_household?
question :how_many_other_children_in_payees_household?
end
end
end
@@ -151,19 +142,14 @@ def define
calculator.rate_type
end

permitted_next_nodes = [
:nil_rate_result,
:flat_rate_result,
:reduced_and_basic_rates_result
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
case rate_type
when :nil
:nil_rate_result
outcome :nil_rate_result
when :flat
:flat_rate_result
outcome :flat_rate_result
else
:reduced_and_basic_rates_result
outcome :reduced_and_basic_rates_result
end
end
end
89 changes: 30 additions & 59 deletions lib/smart_answer_flows/calculate-your-holiday-entitlement.rb
Original file line number Diff line number Diff line change
@@ -26,25 +26,18 @@ def define
nil
end

permitted_next_nodes = [
:calculation_period?,
:casual_or_irregular_hours?,
:annualised_hours?,
:compressed_hours_how_many_hours_per_week?,
:shift_worker_basis?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'days-worked-per-week', 'hours-worked-per-week'
:calculation_period?
question :calculation_period?
when 'casual-or-irregular-hours'
:casual_or_irregular_hours?
question :casual_or_irregular_hours?
when 'annualised-hours'
:annualised_hours?
question :annualised_hours?
when 'compressed-hours'
:compressed_hours_how_many_hours_per_week?
question :compressed_hours_how_many_hours_per_week?
when 'shift-worker'
:shift_worker_basis?
question :shift_worker_basis?
end
end
end
@@ -57,20 +50,18 @@ def define
option "starting-and-leaving"
save_input_as :holiday_period

permitted_next_nodes = [
:what_is_your_starting_date?,
:what_is_your_leaving_date?,
:how_many_days_per_week?,
:how_many_hours_per_week?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "starting", "starting-and-leaving"
:what_is_your_starting_date?
question :what_is_your_starting_date?
when "leaving"
:what_is_your_leaving_date?
question :what_is_your_leaving_date?
else
calculation_basis == "days-worked-per-week" ? :how_many_days_per_week? : :how_many_hours_per_week?
if calculation_basis == "days-worked-per-week"
question :how_many_days_per_week?
else
question :how_many_hours_per_week?
end
end
end
end
@@ -91,15 +82,11 @@ def define
to { Date.civil(1.year.since(Date.today).year, 12, 31) }
save_input_as :start_date

permitted_next_nodes = [
:what_is_your_leaving_date?,
:when_does_your_leave_year_start?
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if holiday_period == "starting-and-leaving"
:what_is_your_leaving_date?
question :what_is_your_leaving_date?
else
:when_does_your_leave_year_start?
question :when_does_your_leave_year_start?
end
end
end
@@ -110,24 +97,18 @@ def define
to { Date.civil(1.year.since(Date.today).year, 12, 31) }
save_input_as :leaving_date

permitted_next_nodes = [
:how_many_days_per_week?,
:how_many_hours_per_week?,
:shift_worker_hours_per_shift?,
:when_does_your_leave_year_start?
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if holiday_period == "starting-and-leaving"
case calculation_basis
when "days-worked-per-week"
:how_many_days_per_week?
question :how_many_days_per_week?
when "hours-worked-per-week"
:how_many_hours_per_week?
question :how_many_hours_per_week?
when "shift-worker"
:shift_worker_hours_per_shift?
question :shift_worker_hours_per_shift?
end
else
:when_does_your_leave_year_start?
question :when_does_your_leave_year_start?
end
end
end
@@ -138,19 +119,14 @@ def define
to { Date.civil(1.year.since(Date.today).year, 12, 31) }
save_input_as :leave_year_start_date

permitted_next_nodes = [
:how_many_days_per_week?,
:how_many_hours_per_week?,
:shift_worker_hours_per_shift?
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
case calculation_basis
when "days-worked-per-week"
:how_many_days_per_week?
question :how_many_days_per_week?
when "hours-worked-per-week"
:how_many_hours_per_week?
question :how_many_hours_per_week?
when "shift-worker"
:shift_worker_hours_per_shift?
question :shift_worker_hours_per_shift?
end
end
end
@@ -208,19 +184,14 @@ def define
option "starting-and-leaving"
save_input_as :holiday_period

permitted_next_nodes = [
:shift_worker_hours_per_shift?,
:what_is_your_starting_date?,
:what_is_your_leaving_date?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'full-year'
:shift_worker_hours_per_shift?
question :shift_worker_hours_per_shift?
when 'starting', 'starting-and-leaving'
:what_is_your_starting_date?
question :what_is_your_starting_date?
when 'leaving'
:what_is_your_leaving_date?
question :what_is_your_leaving_date?
end
end
end
137 changes: 46 additions & 91 deletions lib/smart_answer_flows/check-uk-visa.rb
Original file line number Diff line number Diff line change
@@ -18,19 +18,14 @@ def define
nil
end

permitted_next_nodes = [
:israeli_document_type?,
:outcome_no_visa_needed,
:purpose_of_visit?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.passport_country = response
if calculator.passport_country_is_israel?
:israeli_document_type?
question :israeli_document_type?
elsif calculator.passport_country_in_eea?
:outcome_no_visa_needed
outcome :outcome_no_visa_needed
else
:purpose_of_visit?
question :purpose_of_visit?
end
end
end
@@ -40,10 +35,9 @@ def define
option :"full-passport"
option :"provisional-passport"

permitted_next_nodes = [:purpose_of_visit?]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.passport_country = 'israel-provisional-passport' if response == 'provisional-passport'
:purpose_of_visit?
question :purpose_of_visit?
end
end

@@ -59,91 +53,73 @@ def define
option :medical
option :diplomatic

permitted_next_nodes = [
:outcome_diplomatic_business,
:outcome_joining_family_m,
:outcome_joining_family_nvn,
:outcome_joining_family_y,
:outcome_marriage,
:outcome_medical_n,
:outcome_medical_y,
:outcome_no_visa_needed,
:outcome_school_n,
:outcome_school_waiver,
:outcome_school_y,
:outcome_standard_visit,
:outcome_taiwan_exception,
:outcome_visit_waiver,
:passing_through_uk_border_control?,
:staying_for_how_long?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.purpose_of_visit_answer = response

if calculator.study_visit? || calculator.work_visit?
next :staying_for_how_long?
next question(:staying_for_how_long?)
end

if calculator.diplomatic_visit?
next :outcome_diplomatic_business
next outcome(:outcome_diplomatic_business)
end

if calculator.school_visit?
if calculator.passport_country_in_electronic_visa_waiver_list?
next :outcome_school_waiver
next outcome(:outcome_school_waiver)
elsif calculator.passport_country_is_taiwan?
next :outcome_taiwan_exception
next outcome(:outcome_taiwan_exception)
elsif calculator.passport_country_in_non_visa_national_list? || calculator.passport_country_in_ukot_list?
next :outcome_school_n
next outcome(:outcome_school_n)
else
next :outcome_school_y
next outcome(:outcome_school_y)
end
end

if calculator.medical_visit?
if calculator.passport_country_in_electronic_visa_waiver_list?
next :outcome_visit_waiver
next outcome(:outcome_visit_waiver)
elsif calculator.passport_country_is_taiwan?
next :outcome_taiwan_exception
next outcome(:outcome_taiwan_exception)
elsif calculator.passport_country_in_non_visa_national_list? || calculator.passport_country_in_ukot_list?
next :outcome_medical_n
next outcome(:outcome_medical_n)
else
next :outcome_medical_y
next outcome(:outcome_medical_y)
end
end

if calculator.tourism_visit?
if calculator.passport_country_in_electronic_visa_waiver_list?
next :outcome_visit_waiver
next outcome(:outcome_visit_waiver)
elsif calculator.passport_country_is_taiwan?
next :outcome_taiwan_exception
next outcome(:outcome_taiwan_exception)
elsif calculator.passport_country_in_non_visa_national_list? || calculator.passport_country_in_ukot_list?
next :outcome_school_n # outcome does not contain school specific content
next outcome(:outcome_school_n) # outcome does not contain school specific content
else
next :outcome_standard_visit
next outcome(:outcome_standard_visit)
end
end

if calculator.marriage_visit?
next :outcome_marriage
next outcome(:outcome_marriage)
end

if calculator.transit_visit?
if calculator.passport_country_in_datv_list? ||
calculator.passport_country_in_visa_national_list? || calculator.passport_country_is_taiwan? || calculator.passport_country_is_venezuela?
next :passing_through_uk_border_control?
next question(:passing_through_uk_border_control?)
else
next :outcome_no_visa_needed
next outcome(:outcome_no_visa_needed)
end
end

if calculator.family_visit?
if calculator.passport_country_in_ukot_list?
next :outcome_joining_family_m
next outcome(:outcome_joining_family_m)
elsif calculator.passport_country_in_non_visa_national_list?
next :outcome_joining_family_nvn
next outcome(:outcome_joining_family_nvn)
else
next :outcome_joining_family_y
next outcome(:outcome_joining_family_y)
end
end
end
@@ -154,38 +130,28 @@ def define
option :yes
option :no

permitted_next_nodes = [
:outcome_no_visa_needed,
:outcome_transit_leaving_airport,
:outcome_transit_leaving_airport_datv,
:outcome_transit_not_leaving_airport,
:outcome_transit_refugee_not_leaving_airport,
:outcome_transit_taiwan,
:outcome_transit_taiwan_through_border_control,
:outcome_transit_venezuela,
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.passing_through_uk_border_control_answer = response

if calculator.passing_through_uk_border_control?
if calculator.passport_country_is_taiwan?
:outcome_transit_taiwan_through_border_control
outcome :outcome_transit_taiwan_through_border_control
elsif calculator.passport_country_in_visa_national_list?
:outcome_transit_leaving_airport
outcome :outcome_transit_leaving_airport
elsif calculator.passport_country_in_datv_list?
:outcome_transit_leaving_airport_datv
outcome :outcome_transit_leaving_airport_datv
end
else
if calculator.passport_country_is_taiwan?
:outcome_transit_taiwan
outcome :outcome_transit_taiwan
elsif calculator.passport_country_is_venezuela?
:outcome_transit_venezuela
outcome :outcome_transit_venezuela
elsif calculator.applicant_is_stateless_or_a_refugee?
:outcome_transit_refugee_not_leaving_airport
outcome :outcome_transit_refugee_not_leaving_airport
elsif calculator.passport_country_in_datv_list?
:outcome_transit_not_leaving_airport
outcome :outcome_transit_not_leaving_airport
elsif calculator.passport_country_in_visa_national_list?
:outcome_no_visa_needed
outcome :outcome_no_visa_needed
end
end
end
@@ -204,46 +170,35 @@ def define
end
end

permitted_next_nodes = [
:outcome_no_visa_needed,
:outcome_study_m,
:outcome_study_waiver,
:outcome_study_y,
:outcome_taiwan_exception,
:outcome_work_m,
:outcome_work_n,
:outcome_work_waiver,
:outcome_work_y
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'longer_than_six_months'
if calculator.study_visit?
:outcome_study_y #outcome 2 study y
outcome :outcome_study_y #outcome 2 study y
elsif calculator.work_visit?
:outcome_work_y #outcome 4 work y
outcome :outcome_work_y #outcome 4 work y
end
when 'six_months_or_less'
if calculator.study_visit?
if calculator.passport_country_in_electronic_visa_waiver_list?
:outcome_study_waiver
outcome :outcome_study_waiver
elsif calculator.passport_country_is_taiwan?
:outcome_taiwan_exception
outcome :outcome_taiwan_exception
elsif calculator.passport_country_in_datv_list? || calculator.passport_country_in_visa_national_list?
:outcome_study_m #outcome 3 study m visa needed short courses
outcome :outcome_study_m #outcome 3 study m visa needed short courses
elsif calculator.passport_country_in_ukot_list? || calculator.passport_country_in_non_visa_national_list?
:outcome_no_visa_needed #outcome 1 no visa needed
outcome :outcome_no_visa_needed #outcome 1 no visa needed
end
elsif calculator.work_visit?
if calculator.passport_country_in_electronic_visa_waiver_list?
:outcome_work_waiver
outcome :outcome_work_waiver
elsif calculator.passport_country_in_ukot_list? ||
calculator.passport_country_is_taiwan? || calculator.passport_country_in_non_visa_national_list?
#outcome 5.5 work N no visa needed
:outcome_work_n
outcome :outcome_work_n
elsif calculator.passport_country_in_datv_list? || calculator.passport_country_in_visa_national_list?
# outcome 5 work m visa needed short courses
:outcome_work_m
outcome :outcome_work_m
end
end
end
129 changes: 38 additions & 91 deletions lib/smart_answer_flows/childcare-costs-for-tax-credits.rb
Original file line number Diff line number Diff line change
@@ -15,16 +15,12 @@ def define
nil
end

permitted_next_nodes = [
:have_costs_changed?,
:how_often_use_childcare?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
:have_costs_changed? #Q3
question :have_costs_changed? #Q3
when 'no'
:how_often_use_childcare? #Q2
question :how_often_use_childcare? #Q2
end
end
end
@@ -35,19 +31,14 @@ def define
option :regularly_more_than_year
option :only_short_while

permitted_next_nodes = [
:how_often_pay_1?,
:pay_same_each_time?,
:call_helpline_detailed
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'regularly_less_than_year'
:how_often_pay_1? #Q4
question :how_often_pay_1? #Q4
when 'regularly_more_than_year'
:pay_same_each_time? #Q11
question :pay_same_each_time? #Q11
when 'only_short_while'
:call_helpline_detailed #O1
outcome :call_helpline_detailed #O1
end
end
end
@@ -57,16 +48,12 @@ def define
option :yes
option :no

permitted_next_nodes = [
:how_often_pay_2?,
:no_change
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
:how_often_pay_2? #Q5
question :how_often_pay_2? #Q5
when 'no'
:no_change #O2
outcome :no_change #O2
end
end
end
@@ -79,22 +66,16 @@ def define
option :monthly_diff_amount
option :other

permitted_next_nodes = [
:round_up_weekly,
:how_much_52_weeks_1?,
:how_much_each_month?,
:how_much_12_months_1?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'weekly_same_amount'
:round_up_weekly #O3
question :round_up_weekly #O3
when 'weekly_diff_amount'
:how_much_52_weeks_1? #Q7
question :how_much_52_weeks_1? #Q7
when 'monthly_same_amount'
:how_much_each_month? #Q10
question :how_much_each_month? #Q10
when 'monthly_diff_amount', 'other'
:how_much_12_months_1? #Q6
question :how_much_12_months_1? #Q6
end
end
end
@@ -107,22 +88,16 @@ def define
option :monthly_diff_amount
option :other

permitted_next_nodes = [
:new_weekly_costs?,
:how_much_52_weeks_2?,
:new_monthly_cost?,
:how_much_12_months_2?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'weekly_same_amount'
:new_weekly_costs? #Q17
question :new_weekly_costs? #Q17
when 'weekly_diff_amount', 'other'
:how_much_52_weeks_2? #Q8
question :how_much_52_weeks_2? #Q8
when 'monthly_same_amount'
:new_monthly_cost? #Q19
question :new_monthly_cost? #Q19
when 'monthly_diff_amount'
:how_much_12_months_2? #Q9
question :how_much_12_months_2? #Q9
end
end
end
@@ -149,13 +124,9 @@ def define
SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost(response)
end

permitted_next_nodes = [
:no_longer_paying,
:old_weekly_amount_1?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
amount = Money.new(response)
amount == 0 ? :no_longer_paying : :old_weekly_amount_1?
amount == 0 ? outcome(:no_longer_paying) : question(:old_weekly_amount_1?)
end
end

@@ -165,13 +136,9 @@ def define
SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost(response)
end

permitted_next_nodes = [
:no_longer_paying,
:old_weekly_amount_1?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
amount = Money.new(response)
amount == 0 ? :no_longer_paying : :old_weekly_amount_1?
amount == 0 ? outcome(:no_longer_paying) : question(:old_weekly_amount_1?)
end
end

@@ -188,16 +155,12 @@ def define
option :yes
option :no

permitted_next_nodes = [
:how_often_pay_providers?,
:how_much_spent_last_12_months?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
:how_often_pay_providers? #Q12
question :how_often_pay_providers? #Q12
when 'no'
:how_much_spent_last_12_months? #Q16
question :how_much_spent_last_12_months? #Q16
end
end
end
@@ -212,28 +175,20 @@ def define
option :yearly
option :other

permitted_next_nodes = [
:round_up_weekly,
:how_much_fortnightly?,
:how_much_4_weeks?,
:how_much_each_month?,
:call_helpline_plain,
:how_much_yearly?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'weekly'
:round_up_weekly #O3
outcome :round_up_weekly #O3
when 'fortnightly'
:how_much_fortnightly? #Q13
question :how_much_fortnightly? #Q13
when 'every_4_weeks'
:how_much_4_weeks? #Q14
question :how_much_4_weeks? #Q14
when 'every_month'
:how_much_each_month? #Q10
question :how_much_each_month? #Q10
when 'termly', 'other'
:call_helpline_plain #O5
outcome :call_helpline_plain #O5
when 'yearly'
:how_much_yearly? #Q15
question :how_much_yearly? #Q15
end
end
end
@@ -277,13 +232,9 @@ def define
Float(response).ceil
end

permitted_next_nodes = [
:no_longer_paying,
:old_weekly_amount_2?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
amount = Money.new(response)
amount == 0 ? :no_longer_paying : :old_weekly_amount_2?
amount == 0 ? outcome(:no_longer_paying) : question(:old_weekly_amount_2?)
end
end

@@ -312,13 +263,9 @@ def define
SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost_from_monthly(response)
end

permitted_next_nodes = [
:no_longer_paying,
:old_weekly_amount_3?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
amount = Money.new(response)
amount == 0 ? :no_longer_paying : :old_weekly_amount_3?
amount == 0 ? outcome(:no_longer_paying) : question(:old_weekly_amount_3?)
end
end

143 changes: 45 additions & 98 deletions lib/smart_answer_flows/energy-grants-calculator.rb
Original file line number Diff line number Diff line change
@@ -44,16 +44,12 @@ def define
''
end

permitted_next_nodes = [
:what_are_your_circumstances?,
:what_are_your_circumstances_without_bills_help?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'help_with_fuel_bill'
:what_are_your_circumstances? # Q2
question :what_are_your_circumstances? # Q2
else
:what_are_your_circumstances_without_bills_help? # Q2A
question :what_are_your_circumstances_without_bills_help? # Q2A
end
end
end
@@ -101,19 +97,14 @@ def define
%w(help_energy_efficiency help_boiler_measure).include?(which_help)
}

permitted_next_nodes = [
:date_of_birth?,
:which_benefits?,
:when_property_built?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if both_help
:date_of_birth?
question :date_of_birth?
elsif measure
if response == 'benefits'
:which_benefits?
question :which_benefits?
else
:when_property_built?
question :when_property_built?
end
end
end
@@ -132,18 +123,13 @@ def define
end
end

permitted_next_nodes = [
:which_benefits?,
:outcome_help_with_bills,
:when_property_built?
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if circumstances.include?('benefits')
:which_benefits?
question :which_benefits?
elsif bills_help
:outcome_help_with_bills # outcome 1
outcome :outcome_help_with_bills # outcome 1
else
:when_property_built? # Q6
question :when_property_built? # Q6
end
end
end
@@ -180,24 +166,19 @@ def define
%w{child_tax_credit esa jsa pension_credit}.all? {|key| response.include? key}
end

permitted_next_nodes = [
:outcome_help_with_bills,
:when_property_built?,
:disabled_or_have_children?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if %w{pension_credit child_tax_credit}.include?(response)
if bills_help
:outcome_help_with_bills # outcome 1
outcome :outcome_help_with_bills # outcome 1
else
:when_property_built? # Q6
question :when_property_built? # Q6
end
elsif disabled_or_have_children_question
:disabled_or_have_children? # Q5
question :disabled_or_have_children? # Q5
elsif bills_help
:outcome_help_with_bills # outcome 1
outcome :outcome_help_with_bills # outcome 1
else
:when_property_built? # Q6
question :when_property_built? # Q6
end
end
end
@@ -232,15 +213,11 @@ def define
response != 'none' && benefits_claimed.include?('universal_credit')
end

permitted_next_nodes = [
:outcome_help_with_bills,
:when_property_built?
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if bills_help
:outcome_help_with_bills # outcome 1
outcome :outcome_help_with_bills # outcome 1
else
:when_property_built? # Q6
question :when_property_built? # Q6
end
end
end
@@ -271,24 +248,18 @@ def define
option :flat
save_input_as :property_type

permitted_next_nodes = [
:home_features_modern?,
:home_features_older?,
:home_features_historic?,
:type_of_flat?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'house'
if modern
:home_features_modern?
question :home_features_modern?
elsif older
:home_features_older?
question :home_features_older?
else
:home_features_historic?
question :home_features_historic?
end
else
:type_of_flat?
question :type_of_flat?
end
end
end
@@ -299,18 +270,13 @@ def define
option :ground_floor
save_input_as :flat_type

permitted_next_nodes = [
:home_features_modern?,
:home_features_older?,
:home_features_historic?
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if modern
:home_features_modern?
question :home_features_modern?
elsif older
:home_features_older?
question :home_features_older?
else
:home_features_historic?
question :home_features_historic?
end
end
end
@@ -340,24 +306,17 @@ def define
(circumstances & %w(property permission)).any? and ((benefits_claimed & %w(child_tax_credit esa pension_credit)).any? or incomesupp_jobseekers_1 or incomesupp_jobseekers_2)
end

permitted_next_nodes = [
:outcome_no_green_deal_no_energy_measures,
:outcome_measures_help_green_deal,
:outcome_bills_and_measures_no_benefits,
:outcome_bills_and_measures_on_benefits_eco_eligible,
:outcome_bills_and_measures_on_benefits_not_eco_eligible
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if modern_and_gas_and_electric_heating
:outcome_no_green_deal_no_energy_measures
outcome :outcome_no_green_deal_no_energy_measures
elsif measure_help_and_property_permission_circumstance
:outcome_measures_help_green_deal
outcome :outcome_measures_help_green_deal
elsif no_benefits
:outcome_bills_and_measures_no_benefits
outcome :outcome_bills_and_measures_no_benefits
elsif property_permission_circumstance_and_benefits
:outcome_bills_and_measures_on_benefits_eco_eligible
outcome :outcome_bills_and_measures_on_benefits_eco_eligible
else
:outcome_bills_and_measures_on_benefits_not_eco_eligible
outcome :outcome_bills_and_measures_on_benefits_not_eco_eligible
end
end
end
@@ -387,21 +346,15 @@ def define
(circumstances & %w(property permission)).any? and ((benefits_claimed & %w(child_tax_credit esa pension_credit)).any? or incomesupp_jobseekers_1 or incomesupp_jobseekers_2)
end

permitted_next_nodes = [
:outcome_measures_help_green_deal,
:outcome_bills_and_measures_no_benefits,
:outcome_bills_and_measures_on_benefits_eco_eligible,
:outcome_bills_and_measures_on_benefits_not_eco_eligible
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if measure_help_and_property_permission_circumstance
:outcome_measures_help_green_deal
outcome :outcome_measures_help_green_deal
elsif no_benefits
:outcome_bills_and_measures_no_benefits
outcome :outcome_bills_and_measures_no_benefits
elsif property_permission_circumstance_and_benefits
:outcome_bills_and_measures_on_benefits_eco_eligible
outcome :outcome_bills_and_measures_on_benefits_eco_eligible
else
:outcome_bills_and_measures_on_benefits_not_eco_eligible
outcome :outcome_bills_and_measures_on_benefits_not_eco_eligible
end
end
end
@@ -432,21 +385,15 @@ def define
(circumstances & %w(property permission)).any? and ((benefits_claimed & %w(child_tax_credit esa pension_credit)).any? or incomesupp_jobseekers_1 or incomesupp_jobseekers_2)
end

permitted_next_nodes = [
:outcome_measures_help_green_deal,
:outcome_bills_and_measures_no_benefits,
:outcome_bills_and_measures_on_benefits_eco_eligible,
:outcome_bills_and_measures_on_benefits_not_eco_eligible
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if measure_help_and_property_permission_circumstance
:outcome_measures_help_green_deal
outcome :outcome_measures_help_green_deal
elsif no_benefits
:outcome_bills_and_measures_no_benefits
outcome :outcome_bills_and_measures_no_benefits
elsif property_permission_circumstance_and_benefits
:outcome_bills_and_measures_on_benefits_eco_eligible
outcome :outcome_bills_and_measures_on_benefits_eco_eligible
else
:outcome_bills_and_measures_on_benefits_not_eco_eligible
outcome :outcome_bills_and_measures_on_benefits_not_eco_eligible
end
end
end
15 changes: 5 additions & 10 deletions lib/smart_answer_flows/estimate-self-assessment-penalties.rb
Original file line number Diff line number Diff line change
@@ -75,12 +75,11 @@ def define
filing_date.strftime("%e %B %Y")
end

permitted_next_nodes = [:when_paid?]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response < start_of_next_tax_year
raise SmartAnswer::InvalidResponse
else
:when_paid?
question :when_paid?
end
end
end
@@ -91,11 +90,7 @@ def define

save_input_as :payment_date

permitted_next_nodes = [
:filed_and_paid_on_time,
:how_much_tax?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if filing_date > response
raise SmartAnswer::InvalidResponse
else
@@ -107,9 +102,9 @@ def define
tax_year: tax_year
)
if calculator.paid_on_time?
:filed_and_paid_on_time
outcome :filed_and_paid_on_time
else
:how_much_tax?
question :how_much_tax?
end
end
end
13 changes: 4 additions & 9 deletions lib/smart_answer_flows/help-if-you-are-arrested-abroad.rb
Original file line number Diff line number Diff line change
@@ -77,18 +77,13 @@ def define
links
end

permitted_next_nodes = [
:answer_two_iran,
:answer_three_syria,
:answer_one_generic
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response == "iran"
:answer_two_iran
outcome :answer_two_iran
elsif response == "syria"
:answer_three_syria
outcome :answer_three_syria
else
:answer_one_generic
outcome :answer_one_generic
end
end

211 changes: 72 additions & 139 deletions lib/smart_answer_flows/inherits-someone-dies-without-will.rb

Large diffs are not rendered by default.

162 changes: 49 additions & 113 deletions lib/smart_answer_flows/landlord-immigration-check.rb
Original file line number Diff line number Diff line change
@@ -7,20 +7,15 @@ def define
satisfies_need "102373"

postcode_question :property? do
permitted_next_nodes = [
:main_home?,
:outcome_check_not_needed
]

next_node_calculation :calculator do |response|
Calculators::LandlordImmigrationCheckCalculator.new(response)
end

next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do
if calculator.included_country?
:main_home?
question :main_home?
else
:outcome_check_not_needed
outcome :outcome_check_not_needed
end
end
end
@@ -29,16 +24,12 @@ def define
option "yes"
option "no"

permitted_next_nodes = [
:tenant_over_18?,
:property_type?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "yes"
:tenant_over_18?
question :tenant_over_18?
when "no"
:property_type?
question :property_type?
end
end
end
@@ -47,16 +38,12 @@ def define
option "yes"
option "no"

permitted_next_nodes = [
:has_uk_passport?,
:outcome_check_not_needed_when_under_18
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "yes"
:has_uk_passport?
question :has_uk_passport?
when "no"
:outcome_check_not_needed_when_under_18
outcome :outcome_check_not_needed_when_under_18
end
end
end
@@ -71,34 +58,24 @@ def define
option "student_accommodation"
option "7_year_lease_property"

permitted_next_nodes = [
:outcome_check_not_needed_if_holiday_or_under_3_months,
:outcome_check_not_needed,
:outcome_check_not_needed_when_care_home,
:outcome_check_not_needed_when_hostel_refuge,
:outcome_check_not_needed_when_mobile_home,
:outcome_check_not_needed_when_employee_home,
:outcome_check_may_be_needed_when_student,
:outcome_check_needed_if_break_clause
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "holiday_accommodation"
:outcome_check_not_needed_if_holiday_or_under_3_months
outcome :outcome_check_not_needed_if_holiday_or_under_3_months
when "social_housing"
:outcome_check_not_needed
outcome :outcome_check_not_needed
when "care_home"
:outcome_check_not_needed_when_care_home
outcome :outcome_check_not_needed_when_care_home
when "hostel_or_refuge"
:outcome_check_not_needed_when_hostel_refuge
outcome :outcome_check_not_needed_when_hostel_refuge
when "mobile_home"
:outcome_check_not_needed_when_mobile_home
outcome :outcome_check_not_needed_when_mobile_home
when "employee_accommodation"
:outcome_check_not_needed_when_employee_home
outcome :outcome_check_not_needed_when_employee_home
when "student_accommodation"
:outcome_check_may_be_needed_when_student
outcome :outcome_check_may_be_needed_when_student
when "7_year_lease_property"
:outcome_check_needed_if_break_clause
outcome :outcome_check_needed_if_break_clause
end
end
end
@@ -107,16 +84,12 @@ def define
option "yes"
option "no"

permitted_next_nodes = [
:outcome_can_rent,
:right_to_abode?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "yes"
:outcome_can_rent
outcome :outcome_can_rent
when "no"
:right_to_abode?
question :right_to_abode?
end
end
end
@@ -125,16 +98,12 @@ def define
option "yes"
option "no"

permitted_next_nodes = [
:outcome_can_rent,
:has_certificate?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "yes"
:outcome_can_rent
outcome :outcome_can_rent
when "no"
:has_certificate?
question :has_certificate?
end
end
end
@@ -143,16 +112,12 @@ def define
option "yes"
option "no"

permitted_next_nodes = [
:outcome_can_rent,
:tenant_country?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "yes"
:outcome_can_rent
outcome :outcome_can_rent
when "no"
:tenant_country?
question :tenant_country?
end
end
end
@@ -162,19 +127,14 @@ def define
option "non_eea_but_with_eu_eea_switzerland_family_member"
option "somewhere_else"

permitted_next_nodes = [
:has_documents?,
:has_residence_card_or_eu_eea_swiss_family_member?,
:has_other_documents?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "eu_eea_switzerland"
:has_documents?
question :has_documents?
when "non_eea_but_with_eu_eea_switzerland_family_member"
:has_residence_card_or_eu_eea_swiss_family_member?
question :has_residence_card_or_eu_eea_swiss_family_member?
when "somewhere_else"
:has_other_documents?
question :has_other_documents?
end
end
end
@@ -183,16 +143,12 @@ def define
option "yes"
option "no"

permitted_next_nodes = [
:outcome_can_rent,
:has_other_documents?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "yes"
:outcome_can_rent
outcome :outcome_can_rent
when "no"
:has_other_documents?
question :has_other_documents?
end
end
end
@@ -201,16 +157,12 @@ def define
option "yes"
option "no"

permitted_next_nodes = [
:outcome_can_rent,
:time_limited_to_remain?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "yes"
:outcome_can_rent
outcome :outcome_can_rent
when "no"
:time_limited_to_remain?
question :time_limited_to_remain?
end
end
end
@@ -219,16 +171,12 @@ def define
option "yes"
option "no"

permitted_next_nodes = [
:outcome_can_rent_for_12_months,
:immigration_application?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "yes"
:outcome_can_rent_for_12_months
outcome :outcome_can_rent_for_12_months
when "no"
:immigration_application?
question :immigration_application?
end
end
end
@@ -237,16 +185,12 @@ def define
option "yes"
option "no"

permitted_next_nodes = [
:outcome_can_rent_but_check_will_be_needed_again,
:has_residence_card_or_eu_eea_swiss_family_member?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "yes"
:outcome_can_rent_but_check_will_be_needed_again
outcome :outcome_can_rent_but_check_will_be_needed_again
when "no"
:has_residence_card_or_eu_eea_swiss_family_member?
question :has_residence_card_or_eu_eea_swiss_family_member?
end
end
end
@@ -255,16 +199,12 @@ def define
option "yes"
option "no"

permitted_next_nodes = [
:outcome_can_rent_for_12_months,
:outcome_can_not_rent
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "yes"
:outcome_can_rent_for_12_months
outcome :outcome_can_rent_for_12_months
when "no"
:outcome_can_not_rent
outcome :outcome_can_not_rent
end
end
end
@@ -273,16 +213,12 @@ def define
option "yes"
option "no"

permitted_next_nodes = [
:outcome_can_rent,
:has_asylum_card?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when "yes"
:outcome_can_rent
outcome :outcome_can_rent
when "no"
:has_asylum_card?
question :has_asylum_card?
end
end
end
172 changes: 59 additions & 113 deletions lib/smart_answer_flows/marriage-abroad.rb
Original file line number Diff line number Diff line change
@@ -23,22 +23,16 @@ def define
Calculators::MarriageAbroadCalculator.new
end

permitted_next_nodes = [
:legal_residency?,
:marriage_or_pacs?,
:outcome_os_france_or_fot,
:partner_opposite_or_same_sex?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.ceremony_country = response
if calculator.ceremony_country == 'ireland'
:partner_opposite_or_same_sex?
question :partner_opposite_or_same_sex?
elsif %w(france monaco new-caledonia wallis-and-futuna).include?(calculator.ceremony_country)
:marriage_or_pacs?
question :marriage_or_pacs?
elsif calculator.ceremony_country_is_french_overseas_territory?
:outcome_os_france_or_fot
outcome :outcome_os_france_or_fot
else
:legal_residency?
question :legal_residency?
end
end
end
@@ -49,16 +43,12 @@ def define
option :ceremony_country
option :third_country

permitted_next_nodes = [
:partner_opposite_or_same_sex?,
:what_is_your_partners_nationality?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.resident_of = response
if calculator.ceremony_country == 'switzerland'
:partner_opposite_or_same_sex?
question :partner_opposite_or_same_sex?
else
:what_is_your_partners_nationality?
question :what_is_your_partners_nationality?
end
end
end
@@ -68,19 +58,14 @@ def define
option :marriage
option :pacs

permitted_next_nodes = [
:outcome_cp_france_pacs,
:outcome_monaco,
:outcome_os_france_or_fot
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.marriage_or_pacs = response
if calculator.ceremony_country == 'monaco'
:outcome_monaco
outcome :outcome_monaco
elsif calculator.want_to_get_married?
:outcome_os_france_or_fot
outcome :outcome_os_france_or_fot
else
:outcome_cp_france_pacs
outcome :outcome_cp_france_pacs
end
end
end
@@ -91,9 +76,9 @@ def define
option :partner_local
option :partner_other

next_node(permitted: [:partner_opposite_or_same_sex?]) do |response|
next_node(permitted: :auto) do |response|
calculator.partner_nationality = response
:partner_opposite_or_same_sex?
question :partner_opposite_or_same_sex?
end
end

@@ -102,158 +87,119 @@ def define
option :opposite_sex
option :same_sex

permitted_next_nodes = [
:outcome_brazil_not_living_in_the_uk,
:outcome_consular_cni_os_residing_in_third_country,
:outcome_cp_all_other_countries,
:outcome_cp_commonwealth_countries,
:outcome_cp_consular,
:outcome_cp_no_cni,
:outcome_cp_or_equivalent,
:outcome_ireland,
:outcome_marriage_via_local_authorities,
:outcome_os_affirmation,
:outcome_os_belarus,
:outcome_os_bot,
:outcome_os_cambodia,
:outcome_os_colombia,
:outcome_os_commonwealth,
:outcome_os_consular_cni,
:outcome_os_germany,
:outcome_os_hong_kong,
:outcome_os_indonesia,
:outcome_os_italy,
:outcome_os_kosovo,
:outcome_os_kuwait,
:outcome_os_laos,
:outcome_os_japan,
:outcome_os_marriage_impossible_no_laos_locals,
:outcome_os_no_cni,
:outcome_os_oman,
:outcome_os_other_countries,
:outcome_os_poland,
:outcome_os_slovenia,
:outcome_portugal,
:outcome_spain,
:outcome_ss_affirmation,
:outcome_ss_marriage,
:outcome_ss_marriage_malta,
:outcome_ss_marriage_not_possible,
:outcome_switzerland
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.sex_of_your_partner = response
if calculator.ceremony_country == 'brazil' && calculator.resident_outside_of_uk?
:outcome_brazil_not_living_in_the_uk
outcome :outcome_brazil_not_living_in_the_uk
elsif calculator.ceremony_country == "netherlands"
:outcome_marriage_via_local_authorities
outcome :outcome_marriage_via_local_authorities
elsif calculator.ceremony_country == "portugal"
:outcome_portugal
outcome :outcome_portugal
elsif calculator.ceremony_country == "ireland"
:outcome_ireland
outcome :outcome_ireland
elsif calculator.ceremony_country == "switzerland"
:outcome_switzerland
outcome :outcome_switzerland
elsif calculator.ceremony_country == "spain"
:outcome_spain
outcome :outcome_spain
elsif calculator.partner_is_opposite_sex?
if calculator.ceremony_country == 'hong-kong'
:outcome_os_hong_kong
outcome :outcome_os_hong_kong
elsif calculator.ceremony_country == 'germany'
:outcome_os_germany
outcome :outcome_os_germany
elsif calculator.ceremony_country == 'oman'
:outcome_os_oman
outcome :outcome_os_oman
elsif calculator.ceremony_country == 'belarus'
:outcome_os_belarus
outcome :outcome_os_belarus
elsif calculator.ceremony_country == 'kuwait'
:outcome_os_kuwait
outcome :outcome_os_kuwait
elsif calculator.ceremony_country == 'japan'
:outcome_os_japan
outcome :outcome_os_japan
elsif calculator.resident_of_third_country? &&
(
calculator.opposite_sex_consular_cni_country? ||
%w(kosovo).include?(calculator.ceremony_country) ||
calculator.opposite_sex_consular_cni_in_nearby_country?
)
:outcome_consular_cni_os_residing_in_third_country
outcome :outcome_consular_cni_os_residing_in_third_country
elsif calculator.ceremony_country == 'norway' && calculator.resident_of_third_country?
:outcome_consular_cni_os_residing_in_third_country
outcome :outcome_consular_cni_os_residing_in_third_country
elsif calculator.ceremony_country == 'italy'
:outcome_os_italy
outcome :outcome_os_italy
elsif calculator.ceremony_country == 'cambodia'
:outcome_os_cambodia
outcome :outcome_os_cambodia
elsif calculator.ceremony_country == "colombia"
:outcome_os_colombia
outcome :outcome_os_colombia
elsif calculator.ceremony_country == 'germany'
:outcome_os_germany
outcome :outcome_os_germany
elsif calculator.ceremony_country == "kosovo"
:outcome_os_kosovo
outcome :outcome_os_kosovo
elsif calculator.ceremony_country == "indonesia"
:outcome_os_indonesia
outcome :outcome_os_indonesia
elsif calculator.ceremony_country == "laos" && calculator.partner_is_not_national_of_ceremony_country?
:outcome_os_marriage_impossible_no_laos_locals
outcome :outcome_os_marriage_impossible_no_laos_locals
elsif calculator.ceremony_country == "laos"
:outcome_os_laos
outcome :outcome_os_laos
elsif calculator.ceremony_country == 'poland'
:outcome_os_poland
outcome :outcome_os_poland
elsif calculator.ceremony_country == 'slovenia'
:outcome_os_slovenia
outcome :outcome_os_slovenia
elsif calculator.opposite_sex_consular_cni_country? ||
(
calculator.resident_of_uk? &&
calculator.opposite_sex_no_marriage_related_consular_services_in_ceremony_country?
) ||
calculator.opposite_sex_consular_cni_in_nearby_country?
:outcome_os_consular_cni
outcome :outcome_os_consular_cni
elsif calculator.ceremony_country == "finland" && calculator.resident_of_uk?
:outcome_os_consular_cni
outcome :outcome_os_consular_cni
elsif calculator.ceremony_country == "norway" && calculator.resident_of_uk?
:outcome_os_consular_cni
outcome :outcome_os_consular_cni
elsif calculator.opposite_sex_affirmation_country?
:outcome_os_affirmation
outcome :outcome_os_affirmation
elsif calculator.ceremony_country_in_the_commonwealth? ||
calculator.ceremony_country == 'zimbabwe'
:outcome_os_commonwealth
outcome :outcome_os_commonwealth
elsif calculator.ceremony_country_is_british_overseas_territory?
:outcome_os_bot
outcome :outcome_os_bot
elsif calculator.opposite_sex_no_consular_cni_country? ||
(
calculator.resident_outside_of_uk? &&
calculator.opposite_sex_no_marriage_related_consular_services_in_ceremony_country?
)
:outcome_os_no_cni
outcome :outcome_os_no_cni
elsif calculator.opposite_sex_marriage_via_local_authorities?
:outcome_marriage_via_local_authorities
outcome :outcome_marriage_via_local_authorities
elsif calculator.opposite_sex_in_other_countries?
:outcome_os_other_countries
outcome :outcome_os_other_countries
end
elsif calculator.partner_is_same_sex?
if %w(belgium norway).include?(calculator.ceremony_country)
:outcome_ss_affirmation
outcome :outcome_ss_affirmation
elsif calculator.same_sex_ceremony_country_unknown_or_has_no_embassies?
:outcome_os_no_cni
outcome :outcome_os_no_cni
elsif calculator.ceremony_country == "malta"
:outcome_ss_marriage_malta
outcome :outcome_ss_marriage_malta
elsif calculator.same_sex_marriage_not_possible?
:outcome_ss_marriage_not_possible
outcome :outcome_ss_marriage_not_possible
elsif calculator.ceremony_country == "germany" && calculator.partner_is_national_of_ceremony_country?
:outcome_cp_or_equivalent
outcome :outcome_cp_or_equivalent
elsif calculator.same_sex_marriage_country? ||
(
calculator.same_sex_marriage_country_when_couple_british? &&
calculator.partner_british?
) ||
calculator.same_sex_marriage_and_civil_partnership?
:outcome_ss_marriage
outcome :outcome_ss_marriage
elsif calculator.civil_partnership_equivalent_country?
:outcome_cp_or_equivalent
outcome :outcome_cp_or_equivalent
elsif calculator.civil_partnership_cni_not_required_country?
:outcome_cp_no_cni
outcome :outcome_cp_no_cni
elsif %w(canada south-africa).include?(calculator.ceremony_country)
:outcome_cp_commonwealth_countries
outcome :outcome_cp_commonwealth_countries
elsif calculator.civil_partnership_consular_country?
:outcome_cp_consular
outcome :outcome_cp_consular
else
:outcome_cp_all_other_countries
outcome :outcome_cp_all_other_countries
end
end
end
13 changes: 4 additions & 9 deletions lib/smart_answer_flows/maternity-paternity-calculator.rb
Original file line number Diff line number Diff line change
@@ -47,19 +47,14 @@ def define
nil
end

permitted_next_nodes = [
:baby_due_date_maternity?,
:leave_or_pay_for_adoption?,
:taking_paternity_leave_for_adoption?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'maternity'
:baby_due_date_maternity?
question :baby_due_date_maternity?
when 'paternity'
:leave_or_pay_for_adoption?
question :leave_or_pay_for_adoption?
when 'adoption'
:taking_paternity_leave_for_adoption?
question :taking_paternity_leave_for_adoption?
end
end
end
22 changes: 6 additions & 16 deletions lib/smart_answer_flows/minimum-wage-calculator-employers.rb
Original file line number Diff line number Diff line change
@@ -19,17 +19,12 @@ def define
nil
end

permitted_next_nodes = [
:are_you_an_apprentice?,
:past_payment_date?
]

next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'current_payment'
:are_you_an_apprentice?
question :are_you_an_apprentice?
when 'past_payment'
:past_payment_date?
question :past_payment_date?
end
end
end
@@ -44,17 +39,12 @@ def define
calculator.valid_age?(response)
end

permitted_next_nodes = [
:under_school_leaving_age,
:how_often_do_you_get_paid?
]

next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.age = response
if calculator.under_school_leaving_age?
:under_school_leaving_age
outcome :under_school_leaving_age
else
:how_often_do_you_get_paid?
question :how_often_do_you_get_paid?
end
end
end
39 changes: 12 additions & 27 deletions lib/smart_answer_flows/overseas-passports.rb
Original file line number Diff line number Diff line change
@@ -41,21 +41,15 @@ def define
%w(british-indian-ocean-territory north-korea south-georgia-and-south-sandwich-islands).include?(response)
end

permitted_next_nodes = [
:cannot_apply,
:which_opt?,
:apply_in_neighbouring_country,
:renewing_replacing_applying?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if ineligible_country
:cannot_apply
outcome :cannot_apply
elsif response == 'the-occupied-palestinian-territories'
:which_opt?
question :which_opt?
elsif apply_in_neighbouring_countries
:apply_in_neighbouring_country
outcome :apply_in_neighbouring_country
else
:renewing_replacing_applying?
question :renewing_replacing_applying?
end
end
end
@@ -151,19 +145,14 @@ def define

save_input_as :child_or_adult

permitted_next_nodes = [
:country_of_birth?,
:ips_application_result_online,
:ips_application_result
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if is_ips_application
if %w(applying renewing_old).include?(application_action)
:country_of_birth?
question :country_of_birth?
elsif ips_result_type == :ips_application_result_online
:ips_application_result_online
outcome :ips_application_result_online
else
:ips_application_result
outcome :ips_application_result
end
end
end
@@ -185,16 +174,12 @@ def define
supporting_documents.split("_")[3]
end

permitted_next_nodes = [
:ips_application_result_online,
:ips_application_result
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if is_ips_application
if ips_result_type == :ips_application_result_online
:ips_application_result_online
outcome :ips_application_result_online
else
:ips_application_result
outcome :ips_application_result
end
end
end
60 changes: 20 additions & 40 deletions lib/smart_answer_flows/part-year-profit-tax-credits.rb
Original file line number Diff line number Diff line change
@@ -15,38 +15,32 @@ def define
Calculators::PartYearProfitTaxCreditsCalculator.new
end

permitted_next_nodes = [:what_date_do_your_accounts_go_up_to?]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.tax_credits_award_ends_on = response
:what_date_do_your_accounts_go_up_to?
question :what_date_do_your_accounts_go_up_to?
end
end

date_question :what_date_do_your_accounts_go_up_to? do
default_year { 0 }

permitted_next_nodes = [:have_you_stopped_trading?]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.accounts_end_month_and_day = response
:have_you_stopped_trading?
question :have_you_stopped_trading?
end
end

multiple_choice :have_you_stopped_trading? do
option "yes"
option "no"

permitted_next_nodes = [
:did_you_start_trading_before_the_relevant_accounting_year?,
:do_your_accounts_cover_a_12_month_period?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response == 'yes'
calculator.stopped_trading = true
:did_you_start_trading_before_the_relevant_accounting_year?
question :did_you_start_trading_before_the_relevant_accounting_year?
elsif response == 'no'
calculator.stopped_trading = false
:do_your_accounts_cover_a_12_month_period?
question :do_your_accounts_cover_a_12_month_period?
end
end
end
@@ -57,15 +51,11 @@ def define

precalculate(:accounting_year_begins_on) { calculator.accounting_year.begins_on }

permitted_next_nodes = [
:when_did_you_stop_trading?,
:when_did_you_start_trading?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response == "yes"
:when_did_you_stop_trading?
question :when_did_you_stop_trading?
elsif response == "no"
:when_did_you_start_trading?
question :when_did_you_start_trading?
end
end
end
@@ -81,10 +71,9 @@ def define
calculator.valid_stopped_trading_date?(response)
end

permitted_next_nodes = [:what_is_your_taxable_profit?]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.stopped_trading_on = response
:what_is_your_taxable_profit?
question :what_is_your_taxable_profit?
end
end

@@ -94,15 +83,11 @@ def define

precalculate(:accounting_year_ends_on) { calculator.accounting_year.ends_on }

permitted_next_nodes = [
:what_is_your_taxable_profit?,
:when_did_you_start_trading?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response == "yes"
:what_is_your_taxable_profit?
question :what_is_your_taxable_profit?
else
:when_did_you_start_trading?
question :when_did_you_start_trading?
end
end
end
@@ -117,16 +102,12 @@ def define
calculator.valid_start_trading_date?(response)
end

permitted_next_nodes = [
:when_did_you_stop_trading?,
:what_is_your_taxable_profit?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.started_trading_on = response
if calculator.stopped_trading
:when_did_you_stop_trading?
question :when_did_you_stop_trading?
else
:what_is_your_taxable_profit?
question :what_is_your_taxable_profit?
end
end
end
@@ -135,10 +116,9 @@ def define
precalculate(:basis_period_begins_on) { calculator.basis_period.begins_on }
precalculate(:basis_period_ends_on) { calculator.basis_period.ends_on }

permitted_next_nodes = [:result]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.taxable_profit = response
:result
outcome :result
end
end

434 changes: 171 additions & 263 deletions lib/smart_answer_flows/pay-leave-for-parents.rb

Large diffs are not rendered by default.

22 changes: 7 additions & 15 deletions lib/smart_answer_flows/pip-checker.rb
Original file line number Diff line number Diff line change
@@ -27,31 +27,23 @@ def define
date_question :what_is_your_dob? do
date_of_birth_defaults

permitted_next_nodes = [
:result_1,
:result_2,
:result_3,
:result_5,
:result_6,
:result_7
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
calculator.dob = response
if getting_dla
if calculator.in_group_65?
:result_6
outcome :result_6
elsif calculator.turning_16_before_oct_2013? || calculator.in_middle_group?
:result_7
outcome :result_7
else
:result_5
outcome :result_5
end
else
if calculator.is_65_or_over?
:result_2
outcome :result_2
elsif calculator.is_16_to_64?
:result_3
outcome :result_3
else
:result_1
outcome :result_1
end
end
end
69 changes: 21 additions & 48 deletions lib/smart_answer_flows/register-a-birth.rb
Original file line number Diff line number Diff line change
@@ -31,18 +31,13 @@ def define
Calculators::RegistrationsDataQuery::COMMONWEALTH_COUNTRIES.include?(response)
end

permitted_next_nodes = [
:commonwealth_result,
:no_embassy_result,
:who_has_british_nationality?
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if country_has_no_embassy
:no_embassy_result
outcome :no_embassy_result
elsif responded_with_commonwealth_country
:commonwealth_result
outcome :commonwealth_result
else
:who_has_british_nationality?
question :who_has_british_nationality?
end
end
end
@@ -56,16 +51,12 @@ def define

save_input_as :british_national_parent

permitted_next_nodes = [
:married_couple_or_civil_partnership?,
:no_registration_result
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'mother', 'father', 'mother_and_father'
:married_couple_or_civil_partnership?
question :married_couple_or_civil_partnership?
when 'neither'
:no_registration_result
outcome :no_registration_result
end
end
end
@@ -79,15 +70,11 @@ def define
response == 'no'
end

permitted_next_nodes = [
:childs_date_of_birth?,
:where_are_you_now?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response == 'no' && british_national_parent == 'father'
:childs_date_of_birth?
question :childs_date_of_birth?
else
:where_are_you_now?
question :where_are_you_now?
end
end
end
@@ -101,15 +88,11 @@ def define
Date.new(2006, 07, 01) > response
end

permitted_next_nodes = [
:homeoffice_result,
:where_are_you_now?
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if before_july_2006
:homeoffice_result
outcome :homeoffice_result
else
:where_are_you_now?
question :where_are_you_now?
end
end
end
@@ -140,21 +123,15 @@ def define
country_of_birth == 'north-korea'
}

permitted_next_nodes = [
:no_birth_certificate_result,
:north_korea_result,
:oru_result,
:which_country?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if no_birth_certificate_exception
:no_birth_certificate_result
outcome :no_birth_certificate_result
elsif response == 'another_country'
:which_country?
question :which_country?
elsif response == 'same_country' && born_in_north_korea
:north_korea_result
outcome :north_korea_result
else
:oru_result
outcome :oru_result
end
end
end
@@ -173,15 +150,11 @@ def define
response == 'north-korea'
}

permitted_next_nodes = [
:north_korea_result,
:oru_result
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if currently_in_north_korea
:north_korea_result
outcome :north_korea_result
else
:oru_result
outcome :oru_result
end
end
end
46 changes: 14 additions & 32 deletions lib/smart_answer_flows/register-a-death.rb
Original file line number Diff line number Diff line change
@@ -19,16 +19,12 @@ def define
option :northern_ireland
option :overseas

permitted_next_nodes = [
:did_the_person_die_at_home_hospital?,
:which_country?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'england_wales', 'scotland', 'northern_ireland'
:did_the_person_die_at_home_hospital?
question :did_the_person_die_at_home_hospital?
when 'overseas'
:which_country?
question :which_country?
end
end
end
@@ -79,18 +75,13 @@ def define
Calculators::RegistrationsDataQuery::COMMONWEALTH_COUNTRIES.include?(response)
end

permitted_next_nodes = [
:commonwealth_result,
:no_embassy_result,
:where_are_you_now?
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if responded_with_commonwealth_country
:commonwealth_result
outcome :commonwealth_result
elsif country_has_no_embassy
:no_embassy_result
outcome :no_embassy_result
else
:where_are_you_now?
question :where_are_you_now?
end
end
end
@@ -113,18 +104,13 @@ def define
country_of_death == 'north-korea'
}

permitted_next_nodes = [
:north_korea_result,
:oru_result,
:which_country_are_you_in_now?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response == 'same_country' && died_in_north_korea
:north_korea_result
outcome :north_korea_result
elsif response == 'another_country'
:which_country_are_you_in_now?
question :which_country_are_you_in_now?
else
:oru_result
outcome :oru_result
end
end
end
@@ -143,15 +129,11 @@ def define
response == 'north-korea'
}

permitted_next_nodes = [
:north_korea_result,
:oru_result
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if currently_in_north_korea
:north_korea_result
outcome :north_korea_result
else
:oru_result
outcome :oru_result
end
end
end
20 changes: 6 additions & 14 deletions lib/smart_answer_flows/report-a-lost-or-stolen-passport.rb
Original file line number Diff line number Diff line change
@@ -14,16 +14,12 @@ def define

save_input_as :location

permitted_next_nodes = [
:complete_LS01_form,
:which_country?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'in_the_uk'
:complete_LS01_form
outcome :complete_LS01_form
when 'abroad'
:which_country?
question :which_country?
end
end
end
@@ -42,15 +38,11 @@ def define

end

permitted_next_nodes = [
:contact_the_embassy,
:contact_the_embassy_canada
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response == 'canada'
:contact_the_embassy_canada
outcome :contact_the_embassy_canada
else
:contact_the_embassy
outcome :contact_the_embassy
end
end
end
63 changes: 19 additions & 44 deletions lib/smart_answer_flows/shared_logic/adoption-calculator.rb
Original file line number Diff line number Diff line change
@@ -3,16 +3,12 @@
option :yes
option :no

permitted_next_nodes = [
:employee_date_matched_paternity_adoption?,
:date_of_adoption_match?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
:employee_date_matched_paternity_adoption? #QAP1
question :employee_date_matched_paternity_adoption? #QAP1
when 'no'
:date_of_adoption_match? # QA1
question :date_of_adoption_match? # QA1
end
end
end
@@ -62,16 +58,12 @@
option :yes
option :no

permitted_next_nodes = [
:adoption_employment_contract?,
:adoption_not_entitled_to_leave_or_pay
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
:adoption_employment_contract?
question :adoption_employment_contract?
when 'no'
:adoption_not_entitled_to_leave_or_pay
outcome :adoption_not_entitled_to_leave_or_pay
end
end
end
@@ -105,15 +97,11 @@
employee_has_contract_adoption == 'no' && response == 'no'
end

permitted_next_nodes = [
:adoption_date_leave_starts?,
:adoption_not_entitled_to_leave_or_pay
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if no_contract_not_on_payroll
:adoption_not_entitled_to_leave_or_pay
outcome :adoption_not_entitled_to_leave_or_pay
else
:adoption_date_leave_starts?
question :adoption_date_leave_starts?
end
end
end
@@ -150,15 +138,11 @@
employee_has_contract_adoption == 'yes' && on_payroll == 'no'
end

permitted_next_nodes = [
:adoption_leave_and_pay,
:last_normal_payday_adoption?
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if has_contract_not_on_payroll
:adoption_leave_and_pay
outcome :adoption_leave_and_pay
else
:last_normal_payday_adoption?
question :last_normal_payday_adoption?
end
end
end
@@ -243,15 +227,11 @@
calculator.average_weekly_earnings < calculator.lower_earning_limit
end

permitted_next_nodes = [
:adoption_leave_and_pay,
:how_do_you_want_the_sap_calculated?
]
next_node(permitted: permitted_next_nodes) do
next_node(permitted: :auto) do
if average_weekly_earnings_under_lower_earning_limit
:adoption_leave_and_pay
outcome :adoption_leave_and_pay
else
:how_do_you_want_the_sap_calculated?
question :how_do_you_want_the_sap_calculated?
end
end
end
@@ -263,18 +243,13 @@

save_input_as :sap_calculation_method

permitted_next_nodes = [
:adoption_leave_and_pay,
:monthly_pay_paternity?,
:next_pay_day_paternity?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response == 'weekly_starting'
:adoption_leave_and_pay
outcome :adoption_leave_and_pay
elsif pay_pattern == 'monthly'
:monthly_pay_paternity?
question :monthly_pay_paternity?
else
:next_pay_day_paternity?
question :next_pay_day_paternity?
end
end
end
49 changes: 15 additions & 34 deletions lib/smart_answer_flows/shared_logic/maternity-calculator.rb
Original file line number Diff line number Diff line change
@@ -74,16 +74,12 @@
response == 'no' ? :not_worked_long_enough : nil
end

permitted_next_nodes = [
:is_the_employee_on_your_payroll?,
:maternity_leave_and_pay_result
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
:is_the_employee_on_your_payroll?
question :is_the_employee_on_your_payroll?
when 'no'
:maternity_leave_and_pay_result
outcome :maternity_leave_and_pay_result
end
end
end
@@ -105,16 +101,12 @@
calculator.format_date_day to_saturday
end

permitted_next_nodes = [
:last_normal_payday?,
:maternity_leave_and_pay_result
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'yes'
:last_normal_payday? # NOTE: goes to shared questions
question :last_normal_payday? # NOTE: goes to shared questions
when 'no'
:maternity_leave_and_pay_result
outcome :maternity_leave_and_pay_result
end
end
end
@@ -189,20 +181,15 @@

save_input_as :smp_calculation_method

permitted_next_nodes = [
:maternity_leave_and_pay_result,
:when_in_the_month_is_the_employee_paid?,
:when_is_your_employees_next_pay_day?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
if response == 'usual_paydates'
if pay_pattern == 'monthly'
:when_in_the_month_is_the_employee_paid?
question :when_in_the_month_is_the_employee_paid?
else
:when_is_your_employees_next_pay_day?
question :when_is_your_employees_next_pay_day?
end
else
:maternity_leave_and_pay_result
outcome :maternity_leave_and_pay_result
end
end
end
@@ -227,22 +214,16 @@

save_input_as :monthly_pay_method

permitted_next_nodes = [
:maternity_leave_and_pay_result,
:what_specific_date_each_month_is_the_employee_paid?,
:what_days_does_the_employee_work?,
:what_particular_day_of_the_month_is_the_employee_paid?
]
next_node(permitted: permitted_next_nodes) do |response|
next_node(permitted: :auto) do |response|
case response
when 'first_day_of_the_month', 'last_day_of_the_month'
:maternity_leave_and_pay_result
outcome :maternity_leave_and_pay_result
when 'specific_date_each_month'
:what_specific_date_each_month_is_the_employee_paid?
question :what_specific_date_each_month_is_the_employee_paid?
when 'last_working_day_of_the_month'
:what_days_does_the_employee_work?
question :what_days_does_the_employee_work?
when 'a_certain_week_day_each_month'
:what_particular_day_of_the_month_is_the_employee_paid?
question :what_particular_day_of_the_month_is_the_employee_paid?
end
end
end
Loading