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 next_node blocks in maternity-paternity-calculator #2104

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
68 changes: 53 additions & 15 deletions lib/smart_answer_flows/shared_logic/adoption-calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,21 @@
calculator.format_date_day to_saturday
end

define_predicate(:no_contract_not_on_payroll?) do |response|
next_node_calculation(:no_contract_not_on_payroll) do |response|
employee_has_contract_adoption == 'no' && response == 'no'
end

next_node_if(:adoption_not_entitled_to_leave_or_pay, no_contract_not_on_payroll?)
next_node :adoption_date_leave_starts?
permitted_next_nodes = [
:adoption_date_leave_starts?,
:adoption_not_entitled_to_leave_or_pay
]
next_node(permitted: permitted_next_nodes) do
if no_contract_not_on_payroll
:adoption_not_entitled_to_leave_or_pay
else
:adoption_date_leave_starts?
end
end
end

## QA6
Expand Down Expand Up @@ -137,12 +146,21 @@
calculator.format_date calculator.a_notice_leave
end

define_predicate(:has_contract_not_on_payroll?) do
next_node_calculation(:has_contract_not_on_payroll) do
employee_has_contract_adoption == 'yes' && on_payroll == 'no'
end

next_node_if(:adoption_leave_and_pay, has_contract_not_on_payroll?)
next_node :last_normal_payday_adoption?
permitted_next_nodes = [
:adoption_leave_and_pay,
:last_normal_payday_adoption?
]
next_node(permitted: permitted_next_nodes) do
if has_contract_not_on_payroll
:adoption_leave_and_pay
else
:last_normal_payday_adoption?
end
end
end

# QA7
Expand Down Expand Up @@ -204,9 +222,9 @@
## QA10
money_question :earnings_for_pay_period_adoption? do

calculate :lower_earning_limit do
sprintf("%.2f", calculator.lower_earning_limit)
end
calculate :lower_earning_limit do
sprintf("%.2f", calculator.lower_earning_limit)
end

calculate :average_weekly_earnings do
sprintf("%.2f", calculator.average_weekly_earnings)
Expand All @@ -221,12 +239,21 @@
calculator
end

define_predicate(:average_weekly_earnings_under_lower_earning_limit?) do
next_node_calculation(:average_weekly_earnings_under_lower_earning_limit) do
calculator.average_weekly_earnings < calculator.lower_earning_limit
end

next_node_if(:adoption_leave_and_pay, average_weekly_earnings_under_lower_earning_limit?)
next_node :how_do_you_want_the_sap_calculated?
permitted_next_nodes = [
:adoption_leave_and_pay,
:how_do_you_want_the_sap_calculated?
]
next_node(permitted: permitted_next_nodes) do
if average_weekly_earnings_under_lower_earning_limit
:adoption_leave_and_pay
else
:how_do_you_want_the_sap_calculated?
end
end
end

## QA11
Expand All @@ -236,9 +263,20 @@

save_input_as :sap_calculation_method

next_node_if(:adoption_leave_and_pay, responded_with('weekly_starting'))
next_node_if(:monthly_pay_paternity?, variable_matches(:pay_pattern, 'monthly')) ## Shared with paternity calculator
next_node :next_pay_day_paternity? ## Shared with paternity calculator
permitted_next_nodes = [
:adoption_leave_and_pay,
:monthly_pay_paternity?,
:next_pay_day_paternity?
]
next_node(permitted: permitted_next_nodes) do |response|
if response == 'weekly_starting'
:adoption_leave_and_pay
elsif pay_pattern == 'monthly'
:monthly_pay_paternity?
else
:next_pay_day_paternity?
end
end
end

outcome :adoption_leave_and_pay do
Expand Down
19 changes: 15 additions & 4 deletions lib/smart_answer_flows/shared_logic/maternity-calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,22 @@

save_input_as :smp_calculation_method

on_condition(responded_with("usual_paydates")) do
next_node_if(:when_in_the_month_is_the_employee_paid?, variable_matches(:pay_pattern, "monthly"))
next_node(:when_is_your_employees_next_pay_day?)
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|
if response == 'usual_paydates'
if pay_pattern == 'monthly'
:when_in_the_month_is_the_employee_paid?
else
:when_is_your_employees_next_pay_day?
end
else
:maternity_leave_and_pay_result
end
end
next_node(:maternity_leave_and_pay_result)
end

## QM11
Expand Down
140 changes: 115 additions & 25 deletions lib/smart_answer_flows/shared_logic/paternity-calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,20 @@
paternity_adoption ? ap_adoption_date_formatted : date_of_birth
end

next_node_if(:employee_still_employed_on_birth_date?, responded_with('yes'))
next_node_if(:paternity_not_entitled_to_leave_or_pay, variable_matches(:has_contract, 'no'))
next_node :employee_start_paternity?
permitted_next_nodes = [
:employee_start_paternity?,
:employee_still_employed_on_birth_date?,
:paternity_not_entitled_to_leave_or_pay
]
next_node(permitted: permitted_next_nodes) do |response|
if response == 'yes'
:employee_still_employed_on_birth_date?
elsif has_contract == 'no'
:paternity_not_entitled_to_leave_or_pay
else
:employee_start_paternity?
end
end
end

## QP7
Expand All @@ -228,8 +239,17 @@
option :no
save_input_as :employed_dob

next_node_if(:paternity_not_entitled_to_leave_or_pay, variable_matches(:has_contract, 'no') & responded_with('no'))
next_node :employee_start_paternity?
permitted_next_nodes = [
:employee_start_paternity?,
:paternity_not_entitled_to_leave_or_pay
]
next_node(permitted: permitted_next_nodes) do |response|
if has_contract == 'no' && response == 'no'
:paternity_not_entitled_to_leave_or_pay
else
:employee_start_paternity?
end
end
end

## QP8
Expand Down Expand Up @@ -267,9 +287,17 @@
calculator.pay_end_date
end

next_node_if(:paternity_not_entitled_to_leave_or_pay, variable_matches(:has_contract, 'yes') &
(variable_matches(:on_payroll, 'no') | variable_matches(:employed_dob, 'no')))
next_node :last_normal_payday_paternity?
permitted_next_nodes = [
:last_normal_payday_paternity?,
:paternity_not_entitled_to_leave_or_pay
]
next_node(permitted: permitted_next_nodes) do
if has_contract == 'yes' && (on_payroll == 'no' || employed_dob == 'no')
:paternity_not_entitled_to_leave_or_pay
else
:last_normal_payday_paternity?
end
end
end

## QP10
Expand Down Expand Up @@ -338,12 +366,21 @@
calculator
end

define_predicate(:average_weekly_earnings_under_lower_earning_limit?) do
next_node_calculation(:average_weekly_earnings_under_lower_earning_limit) do
calculator.average_weekly_earnings < calculator.lower_earning_limit
end

next_node_if(:paternity_leave_and_pay, average_weekly_earnings_under_lower_earning_limit?)
next_node :how_do_you_want_the_spp_calculated?
permitted_next_nodes = [
:how_do_you_want_the_spp_calculated?,
:paternity_leave_and_pay
]
next_node(permitted: permitted_next_nodes) do
if average_weekly_earnings_under_lower_earning_limit
:paternity_leave_and_pay
else
:how_do_you_want_the_spp_calculated?
end
end
end

## QP14
Expand All @@ -353,9 +390,20 @@

save_input_as :spp_calculation_method

next_node_if(:paternity_leave_and_pay, responded_with('weekly_starting'))
next_node_if(:monthly_pay_paternity?, variable_matches(:pay_pattern, 'monthly'))
next_node :next_pay_day_paternity?
permitted_next_nodes = [
:monthly_pay_paternity?,
:next_pay_day_paternity?,
:paternity_leave_and_pay
]
next_node(permitted: permitted_next_nodes) do |response|
if response == 'weekly_starting'
:paternity_leave_and_pay
elsif pay_pattern == 'monthly'
:monthly_pay_paternity?
else
:next_pay_day_paternity?
end
end
end

## QP15 - Also shared with adoption calculator here onwards
Expand All @@ -381,11 +429,26 @@

save_input_as :monthly_pay_method

next_node_if(:specific_date_each_month_paternity?, responded_with('specific_date_each_month'))
next_node_if(:days_of_the_week_paternity?, responded_with('last_working_day_of_the_month'))
next_node_if(:day_of_the_month_paternity?, responded_with('a_certain_week_day_each_month'))
next_node_if(:adoption_leave_and_pay, variable_matches(:leave_type, 'adoption'))
next_node :paternity_leave_and_pay
permitted_next_nodes = [
:adoption_leave_and_pay,
:day_of_the_month_paternity?,
:days_of_the_week_paternity?,
:paternity_leave_and_pay,
:specific_date_each_month_paternity?
]
next_node(permitted: permitted_next_nodes) do |response|
if response == 'specific_date_each_month'
:specific_date_each_month_paternity?
elsif response == 'last_working_day_of_the_month'
:days_of_the_week_paternity?
elsif response == 'a_certain_week_day_each_month'
:day_of_the_month_paternity?
elsif leave_type == 'adoption'
:adoption_leave_and_pay
else
:paternity_leave_and_pay
end
end
end

## QP17
Expand All @@ -397,8 +460,17 @@
calculator.pay_day_in_month = day
end

next_node_if(:adoption_leave_and_pay, variable_matches(:leave_type, 'adoption'))
next_node :paternity_leave_and_pay
permitted_next_nodes = [
:adoption_leave_and_pay,
:paternity_leave_and_pay
]
next_node(permitted: permitted_next_nodes) do
if leave_type == 'adoption'
:adoption_leave_and_pay
else
:paternity_leave_and_pay
end
end
end

## QP18
Expand All @@ -410,8 +482,17 @@
calculator.pay_day_in_week = response.split(",").sort.last.to_i
end

next_node_if(:adoption_leave_and_pay, variable_matches(:leave_type, 'adoption'))
next_node :paternity_leave_and_pay
permitted_next_nodes = [
:adoption_leave_and_pay,
:paternity_leave_and_pay
]
next_node(permitted: permitted_next_nodes) do
if leave_type == 'adoption'
:adoption_leave_and_pay
else
:paternity_leave_and_pay
end
end
end

## QP19
Expand Down Expand Up @@ -444,8 +525,17 @@
calculator.pay_week_in_month = response
end

next_node_if(:adoption_leave_and_pay, variable_matches(:leave_type, 'adoption'))
next_node :paternity_leave_and_pay
permitted_next_nodes = [
:adoption_leave_and_pay,
:paternity_leave_and_pay
]
next_node(permitted: permitted_next_nodes) do
if leave_type == 'adoption'
:adoption_leave_and_pay
else
:paternity_leave_and_pay
end
end
end

# Paternity outcomes
Expand Down
6 changes: 3 additions & 3 deletions test/data/maternity-paternity-calculator-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ lib/smart_answer_flows/maternity-paternity-calculator/questions/what_type_of_lea
lib/smart_answer_flows/maternity-paternity-calculator/questions/when_in_the_month_is_the_employee_paid.govspeak.erb: d540503a4470d20b26ceb4fd5a84a3f4
lib/smart_answer_flows/maternity-paternity-calculator/questions/when_is_your_employees_next_pay_day.govspeak.erb: a74aad333d92213910367be1ecee9e80
lib/smart_answer_flows/maternity-paternity-calculator/questions/which_week_in_month_is_the_employee_paid.govspeak.erb: 19fef5ffcbb85e74f88dd24ce3ccf4c0
lib/smart_answer_flows/shared_logic/adoption-calculator.rb: c166e63f0d4694acc664c789953659ba
lib/smart_answer_flows/shared_logic/maternity-calculator.rb: 5b566b38ef501d2a7c69a5e94ca18c2e
lib/smart_answer_flows/shared_logic/paternity-calculator.rb: b09bdfd9c704ddbe78252173c4ccd0bd
lib/smart_answer_flows/shared_logic/adoption-calculator.rb: 74d75b8b3fd2a62ae177dffce0271b1f
lib/smart_answer_flows/shared_logic/maternity-calculator.rb: 93d151262f844f606f21d711aef31ba7
lib/smart_answer_flows/shared_logic/paternity-calculator.rb: 4db5c4bc2f2e96f52bbdc41d7aa850a5
lib/smart_answer/calculators/maternity_paternity_calculator.rb: 24de99189c23e9a7cc048871a817bb3c
lib/data/rates/maternity_paternity_birth.yml: 3eef956f1020576a9343647fec34dd01
lib/data/rates/maternity_paternity_adoption.yml: 453c4d90b6fd9ffe1556782665f313fc