Skip to content

Commit 76a04ac

Browse files
committed
Merge pull request #2104 from alphagov/use-next-node-blocks-in-maternity-paternity-calculator
Use next_node blocks in maternity-paternity-calculator
2 parents 56d712f + bc998d6 commit 76a04ac

File tree

4 files changed

+186
-47
lines changed

4 files changed

+186
-47
lines changed

lib/smart_answer_flows/shared_logic/adoption-calculator.rb

+53-15
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,21 @@
101101
calculator.format_date_day to_saturday
102102
end
103103

104-
define_predicate(:no_contract_not_on_payroll?) do |response|
104+
next_node_calculation(:no_contract_not_on_payroll) do |response|
105105
employee_has_contract_adoption == 'no' && response == 'no'
106106
end
107107

108-
next_node_if(:adoption_not_entitled_to_leave_or_pay, no_contract_not_on_payroll?)
109-
next_node :adoption_date_leave_starts?
108+
permitted_next_nodes = [
109+
:adoption_date_leave_starts?,
110+
:adoption_not_entitled_to_leave_or_pay
111+
]
112+
next_node(permitted: permitted_next_nodes) do
113+
if no_contract_not_on_payroll
114+
:adoption_not_entitled_to_leave_or_pay
115+
else
116+
:adoption_date_leave_starts?
117+
end
118+
end
110119
end
111120

112121
## QA6
@@ -137,12 +146,21 @@
137146
calculator.format_date calculator.a_notice_leave
138147
end
139148

140-
define_predicate(:has_contract_not_on_payroll?) do
149+
next_node_calculation(:has_contract_not_on_payroll) do
141150
employee_has_contract_adoption == 'yes' && on_payroll == 'no'
142151
end
143152

144-
next_node_if(:adoption_leave_and_pay, has_contract_not_on_payroll?)
145-
next_node :last_normal_payday_adoption?
153+
permitted_next_nodes = [
154+
:adoption_leave_and_pay,
155+
:last_normal_payday_adoption?
156+
]
157+
next_node(permitted: permitted_next_nodes) do
158+
if has_contract_not_on_payroll
159+
:adoption_leave_and_pay
160+
else
161+
:last_normal_payday_adoption?
162+
end
163+
end
146164
end
147165

148166
# QA7
@@ -204,9 +222,9 @@
204222
## QA10
205223
money_question :earnings_for_pay_period_adoption? do
206224

207-
calculate :lower_earning_limit do
208-
sprintf("%.2f", calculator.lower_earning_limit)
209-
end
225+
calculate :lower_earning_limit do
226+
sprintf("%.2f", calculator.lower_earning_limit)
227+
end
210228

211229
calculate :average_weekly_earnings do
212230
sprintf("%.2f", calculator.average_weekly_earnings)
@@ -221,12 +239,21 @@
221239
calculator
222240
end
223241

224-
define_predicate(:average_weekly_earnings_under_lower_earning_limit?) do
242+
next_node_calculation(:average_weekly_earnings_under_lower_earning_limit) do
225243
calculator.average_weekly_earnings < calculator.lower_earning_limit
226244
end
227245

228-
next_node_if(:adoption_leave_and_pay, average_weekly_earnings_under_lower_earning_limit?)
229-
next_node :how_do_you_want_the_sap_calculated?
246+
permitted_next_nodes = [
247+
:adoption_leave_and_pay,
248+
:how_do_you_want_the_sap_calculated?
249+
]
250+
next_node(permitted: permitted_next_nodes) do
251+
if average_weekly_earnings_under_lower_earning_limit
252+
:adoption_leave_and_pay
253+
else
254+
:how_do_you_want_the_sap_calculated?
255+
end
256+
end
230257
end
231258

232259
## QA11
@@ -236,9 +263,20 @@
236263

237264
save_input_as :sap_calculation_method
238265

239-
next_node_if(:adoption_leave_and_pay, responded_with('weekly_starting'))
240-
next_node_if(:monthly_pay_paternity?, variable_matches(:pay_pattern, 'monthly')) ## Shared with paternity calculator
241-
next_node :next_pay_day_paternity? ## Shared with paternity calculator
266+
permitted_next_nodes = [
267+
:adoption_leave_and_pay,
268+
:monthly_pay_paternity?,
269+
:next_pay_day_paternity?
270+
]
271+
next_node(permitted: permitted_next_nodes) do |response|
272+
if response == 'weekly_starting'
273+
:adoption_leave_and_pay
274+
elsif pay_pattern == 'monthly'
275+
:monthly_pay_paternity?
276+
else
277+
:next_pay_day_paternity?
278+
end
279+
end
242280
end
243281

244282
outcome :adoption_leave_and_pay do

lib/smart_answer_flows/shared_logic/maternity-calculator.rb

+15-4
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,22 @@
189189

190190
save_input_as :smp_calculation_method
191191

192-
on_condition(responded_with("usual_paydates")) do
193-
next_node_if(:when_in_the_month_is_the_employee_paid?, variable_matches(:pay_pattern, "monthly"))
194-
next_node(:when_is_your_employees_next_pay_day?)
192+
permitted_next_nodes = [
193+
:maternity_leave_and_pay_result,
194+
:when_in_the_month_is_the_employee_paid?,
195+
:when_is_your_employees_next_pay_day?
196+
]
197+
next_node(permitted: permitted_next_nodes) do |response|
198+
if response == 'usual_paydates'
199+
if pay_pattern == 'monthly'
200+
:when_in_the_month_is_the_employee_paid?
201+
else
202+
:when_is_your_employees_next_pay_day?
203+
end
204+
else
205+
:maternity_leave_and_pay_result
206+
end
195207
end
196-
next_node(:maternity_leave_and_pay_result)
197208
end
198209

199210
## QM11

lib/smart_answer_flows/shared_logic/paternity-calculator.rb

+115-25
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,20 @@
217217
paternity_adoption ? ap_adoption_date_formatted : date_of_birth
218218
end
219219

220-
next_node_if(:employee_still_employed_on_birth_date?, responded_with('yes'))
221-
next_node_if(:paternity_not_entitled_to_leave_or_pay, variable_matches(:has_contract, 'no'))
222-
next_node :employee_start_paternity?
220+
permitted_next_nodes = [
221+
:employee_start_paternity?,
222+
:employee_still_employed_on_birth_date?,
223+
:paternity_not_entitled_to_leave_or_pay
224+
]
225+
next_node(permitted: permitted_next_nodes) do |response|
226+
if response == 'yes'
227+
:employee_still_employed_on_birth_date?
228+
elsif has_contract == 'no'
229+
:paternity_not_entitled_to_leave_or_pay
230+
else
231+
:employee_start_paternity?
232+
end
233+
end
223234
end
224235

225236
## QP7
@@ -228,8 +239,17 @@
228239
option :no
229240
save_input_as :employed_dob
230241

231-
next_node_if(:paternity_not_entitled_to_leave_or_pay, variable_matches(:has_contract, 'no') & responded_with('no'))
232-
next_node :employee_start_paternity?
242+
permitted_next_nodes = [
243+
:employee_start_paternity?,
244+
:paternity_not_entitled_to_leave_or_pay
245+
]
246+
next_node(permitted: permitted_next_nodes) do |response|
247+
if has_contract == 'no' && response == 'no'
248+
:paternity_not_entitled_to_leave_or_pay
249+
else
250+
:employee_start_paternity?
251+
end
252+
end
233253
end
234254

235255
## QP8
@@ -267,9 +287,17 @@
267287
calculator.pay_end_date
268288
end
269289

270-
next_node_if(:paternity_not_entitled_to_leave_or_pay, variable_matches(:has_contract, 'yes') &
271-
(variable_matches(:on_payroll, 'no') | variable_matches(:employed_dob, 'no')))
272-
next_node :last_normal_payday_paternity?
290+
permitted_next_nodes = [
291+
:last_normal_payday_paternity?,
292+
:paternity_not_entitled_to_leave_or_pay
293+
]
294+
next_node(permitted: permitted_next_nodes) do
295+
if has_contract == 'yes' && (on_payroll == 'no' || employed_dob == 'no')
296+
:paternity_not_entitled_to_leave_or_pay
297+
else
298+
:last_normal_payday_paternity?
299+
end
300+
end
273301
end
274302

275303
## QP10
@@ -338,12 +366,21 @@
338366
calculator
339367
end
340368

341-
define_predicate(:average_weekly_earnings_under_lower_earning_limit?) do
369+
next_node_calculation(:average_weekly_earnings_under_lower_earning_limit) do
342370
calculator.average_weekly_earnings < calculator.lower_earning_limit
343371
end
344372

345-
next_node_if(:paternity_leave_and_pay, average_weekly_earnings_under_lower_earning_limit?)
346-
next_node :how_do_you_want_the_spp_calculated?
373+
permitted_next_nodes = [
374+
:how_do_you_want_the_spp_calculated?,
375+
:paternity_leave_and_pay
376+
]
377+
next_node(permitted: permitted_next_nodes) do
378+
if average_weekly_earnings_under_lower_earning_limit
379+
:paternity_leave_and_pay
380+
else
381+
:how_do_you_want_the_spp_calculated?
382+
end
383+
end
347384
end
348385

349386
## QP14
@@ -353,9 +390,20 @@
353390

354391
save_input_as :spp_calculation_method
355392

356-
next_node_if(:paternity_leave_and_pay, responded_with('weekly_starting'))
357-
next_node_if(:monthly_pay_paternity?, variable_matches(:pay_pattern, 'monthly'))
358-
next_node :next_pay_day_paternity?
393+
permitted_next_nodes = [
394+
:monthly_pay_paternity?,
395+
:next_pay_day_paternity?,
396+
:paternity_leave_and_pay
397+
]
398+
next_node(permitted: permitted_next_nodes) do |response|
399+
if response == 'weekly_starting'
400+
:paternity_leave_and_pay
401+
elsif pay_pattern == 'monthly'
402+
:monthly_pay_paternity?
403+
else
404+
:next_pay_day_paternity?
405+
end
406+
end
359407
end
360408

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

382430
save_input_as :monthly_pay_method
383431

384-
next_node_if(:specific_date_each_month_paternity?, responded_with('specific_date_each_month'))
385-
next_node_if(:days_of_the_week_paternity?, responded_with('last_working_day_of_the_month'))
386-
next_node_if(:day_of_the_month_paternity?, responded_with('a_certain_week_day_each_month'))
387-
next_node_if(:adoption_leave_and_pay, variable_matches(:leave_type, 'adoption'))
388-
next_node :paternity_leave_and_pay
432+
permitted_next_nodes = [
433+
:adoption_leave_and_pay,
434+
:day_of_the_month_paternity?,
435+
:days_of_the_week_paternity?,
436+
:paternity_leave_and_pay,
437+
:specific_date_each_month_paternity?
438+
]
439+
next_node(permitted: permitted_next_nodes) do |response|
440+
if response == 'specific_date_each_month'
441+
:specific_date_each_month_paternity?
442+
elsif response == 'last_working_day_of_the_month'
443+
:days_of_the_week_paternity?
444+
elsif response == 'a_certain_week_day_each_month'
445+
:day_of_the_month_paternity?
446+
elsif leave_type == 'adoption'
447+
:adoption_leave_and_pay
448+
else
449+
:paternity_leave_and_pay
450+
end
451+
end
389452
end
390453

391454
## QP17
@@ -397,8 +460,17 @@
397460
calculator.pay_day_in_month = day
398461
end
399462

400-
next_node_if(:adoption_leave_and_pay, variable_matches(:leave_type, 'adoption'))
401-
next_node :paternity_leave_and_pay
463+
permitted_next_nodes = [
464+
:adoption_leave_and_pay,
465+
:paternity_leave_and_pay
466+
]
467+
next_node(permitted: permitted_next_nodes) do
468+
if leave_type == 'adoption'
469+
:adoption_leave_and_pay
470+
else
471+
:paternity_leave_and_pay
472+
end
473+
end
402474
end
403475

404476
## QP18
@@ -410,8 +482,17 @@
410482
calculator.pay_day_in_week = response.split(",").sort.last.to_i
411483
end
412484

413-
next_node_if(:adoption_leave_and_pay, variable_matches(:leave_type, 'adoption'))
414-
next_node :paternity_leave_and_pay
485+
permitted_next_nodes = [
486+
:adoption_leave_and_pay,
487+
:paternity_leave_and_pay
488+
]
489+
next_node(permitted: permitted_next_nodes) do
490+
if leave_type == 'adoption'
491+
:adoption_leave_and_pay
492+
else
493+
:paternity_leave_and_pay
494+
end
495+
end
415496
end
416497

417498
## QP19
@@ -444,8 +525,17 @@
444525
calculator.pay_week_in_month = response
445526
end
446527

447-
next_node_if(:adoption_leave_and_pay, variable_matches(:leave_type, 'adoption'))
448-
next_node :paternity_leave_and_pay
528+
permitted_next_nodes = [
529+
:adoption_leave_and_pay,
530+
:paternity_leave_and_pay
531+
]
532+
next_node(permitted: permitted_next_nodes) do
533+
if leave_type == 'adoption'
534+
:adoption_leave_and_pay
535+
else
536+
:paternity_leave_and_pay
537+
end
538+
end
449539
end
450540

451541
# Paternity outcomes

test/data/maternity-paternity-calculator-files.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ lib/smart_answer_flows/maternity-paternity-calculator/questions/what_type_of_lea
7070
lib/smart_answer_flows/maternity-paternity-calculator/questions/when_in_the_month_is_the_employee_paid.govspeak.erb: d540503a4470d20b26ceb4fd5a84a3f4
7171
lib/smart_answer_flows/maternity-paternity-calculator/questions/when_is_your_employees_next_pay_day.govspeak.erb: a74aad333d92213910367be1ecee9e80
7272
lib/smart_answer_flows/maternity-paternity-calculator/questions/which_week_in_month_is_the_employee_paid.govspeak.erb: 19fef5ffcbb85e74f88dd24ce3ccf4c0
73-
lib/smart_answer_flows/shared_logic/adoption-calculator.rb: c166e63f0d4694acc664c789953659ba
74-
lib/smart_answer_flows/shared_logic/maternity-calculator.rb: 5b566b38ef501d2a7c69a5e94ca18c2e
75-
lib/smart_answer_flows/shared_logic/paternity-calculator.rb: b09bdfd9c704ddbe78252173c4ccd0bd
73+
lib/smart_answer_flows/shared_logic/adoption-calculator.rb: 74d75b8b3fd2a62ae177dffce0271b1f
74+
lib/smart_answer_flows/shared_logic/maternity-calculator.rb: 93d151262f844f606f21d711aef31ba7
75+
lib/smart_answer_flows/shared_logic/paternity-calculator.rb: 4db5c4bc2f2e96f52bbdc41d7aa850a5
7676
lib/smart_answer/calculators/maternity_paternity_calculator.rb: 24de99189c23e9a7cc048871a817bb3c
7777
lib/data/rates/maternity_paternity_birth.yml: 3eef956f1020576a9343647fec34dd01
7878
lib/data/rates/maternity_paternity_adoption.yml: 453c4d90b6fd9ffe1556782665f313fc

0 commit comments

Comments
 (0)