From fd351c0bef9608d8f1353f17fbf9a2c4d3ffcd22 Mon Sep 17 00:00:00 2001 From: ariannedee Date: Mon, 5 Oct 2020 12:49:34 -0700 Subject: [PATCH] DIV-1170: Update requirements for when questions should be hidden --- edivorce/apps/core/utils/conditional_logic.py | 54 ++++- edivorce/apps/core/utils/derived.py | 3 +- edivorce/fixtures/Question.json | 200 +++++++++++------- 3 files changed, 170 insertions(+), 87 deletions(-) diff --git a/edivorce/apps/core/utils/conditional_logic.py b/edivorce/apps/core/utils/conditional_logic.py index 94a1d373..c01009a7 100644 --- a/edivorce/apps/core/utils/conditional_logic.py +++ b/edivorce/apps/core/utils/conditional_logic.py @@ -1,7 +1,24 @@ +import functools import json import re +def no_children(return_val): + def decorator_no_children(func): + @functools.wraps(func) + def inner(questions_dict, *args, **kwargs): + if questions_dict.get('children_of_marriage', '') != 'YES': + return return_val + return func(questions_dict, *args, **kwargs) + return inner + return decorator_no_children + + +def determine_has_children_of_marriage(questions_dict): + return questions_dict.get('children_of_marriage', '') == 'YES' + + +@no_children([]) def get_children(questions_dict): children_json = questions_dict.get('claimant_children', '[]') if isinstance(children_json, dict): @@ -9,25 +26,32 @@ def get_children(questions_dict): return json.loads(children_json) +@no_children('0') def get_num_children_living_with(questions_dict, living_arrangement): assert living_arrangement in ['Lives with you', 'Lives with spouse', 'Lives with both'] children = get_children(questions_dict) return str(len([child for child in children if child['child_live_with'] == living_arrangement])) +@no_children(False) def determine_sole_custody(questions_dict): + """ Return True if all children live with one parent """ child_list = get_children(questions_dict) return (all([child['child_live_with'] == 'Lives with you' for child in child_list]) or all([child['child_live_with'] == 'Lives with spouse' for child in child_list])) +@no_children(False) def determine_shared_custody(questions_dict): + """ Return True if any children live with both parents """ child_list = get_children(questions_dict) return any([child['child_live_with'] == 'Lives with both' for child in child_list]) +@no_children(False) def determine_split_custody(questions_dict): + """ Return True if at least one child lives with one parent and at least one lives with the other (or both) """ child_list = get_children(questions_dict) with_you = 0 with_spouse = 0 @@ -43,14 +67,15 @@ def determine_split_custody(questions_dict): with_spouse > 0 and (with_you + with_both > 0)) +@no_children(False) def determine_child_over_19_supported(questions_dict): - has_children_of_marriage = questions_dict.get('children_of_marriage', '') == 'YES' has_children_over_19 = questions_dict.get('has_children_over_19', '') == 'YES' support = json.loads(questions_dict.get('children_financial_support', '[]')) supporting_children = len(support) > 0 and 'NO' not in support - return has_children_of_marriage and has_children_over_19 and supporting_children + return has_children_over_19 and supporting_children +@no_children(False) def determine_missing_undue_hardship_reasons(questions_dict): claiming_undue_hardship = questions_dict.get('claiming_undue_hardship', '') == 'YES' if claiming_undue_hardship: @@ -73,6 +98,7 @@ def determine_missing_undue_hardship_reasons(questions_dict): return False +@no_children('') def determine_child_support_payor(questions_dict): payor = questions_dict.get('child_support_payor', '') if payor == 'Myself (Claimant 1)': @@ -84,6 +110,7 @@ def determine_child_support_payor(questions_dict): return '' +@no_children(False) def determine_show_fact_sheet_f_you(questions_dict): """ If claimant 1 (you) is a payor and makes over $150,000/year, show fact sheet F for claimant 1 @@ -96,6 +123,7 @@ def determine_show_fact_sheet_f_you(questions_dict): return (payor == 'Claimant 1' or payor == 'both Claimant 1 and Claimant 2') and annual > 150000 +@no_children(False) def determine_show_fact_sheet_f_spouse(questions_dict): """ If claimant 2 (spouse) is a payor and makes over $150,000/year, show fact sheet F for claimant 2 @@ -110,11 +138,13 @@ def determine_show_fact_sheet_f_spouse(questions_dict): return (payor == 'Claimant 2' or payor == 'both Claimant 1 and Claimant 2') and annual > 150000 +@no_children(False) def determine_child_support_act_requirement(questions_dict): orders_wanted = json.loads(questions_dict.get('want_which_orders', '[]')) return 'Child support' in orders_wanted +@no_children(False) def determine_missing_extraordinary_expenses(questions_dict): special_expenses_keys = ["child_care_expenses", "children_healthcare_premiums", @@ -137,11 +167,27 @@ def determine_missing_extraordinary_expenses(questions_dict): return False +@no_children(False) def determine_show_children_live_with_others(questions_dict): - has_children_of_marriage = questions_dict.get('children_of_marriage', '') == 'YES' has_children_under_19 = questions_dict.get('has_children_under_19', '') == 'YES' child_over_19_supported = determine_child_over_19_supported(questions_dict) - return has_children_of_marriage and (has_children_under_19 or child_over_19_supported) + return has_children_under_19 or child_over_19_supported + + +def orders_wanted(questions_dict): + return json.loads(questions_dict.get('want_which_orders', '[]')) + + +def determine_spousal_support_orders_wanted(questions_dict): + return 'Spousal support' in orders_wanted(questions_dict) + + +def determine_property_debt_orders_wanted(questions_dict): + return 'Division of property and debts' in orders_wanted(questions_dict) + + +def determine_other_orders_wanted(questions_dict): + return 'Other orders' in orders_wanted(questions_dict) def get_cleaned_response_value(response): diff --git a/edivorce/apps/core/utils/derived.py b/edivorce/apps/core/utils/derived.py index 2bd720f4..b8a1907e 100644 --- a/edivorce/apps/core/utils/derived.py +++ b/edivorce/apps/core/utils/derived.py @@ -106,8 +106,7 @@ def get_derived_data(responses): def orders_wanted(responses, derived): """ Return a list of orders the user has indicated """ - - return json.loads(responses.get('want_which_orders', '[]')) + return conditional_logic.orders_wanted(responses) def children(responses, derived): diff --git a/edivorce/fixtures/Question.json b/edivorce/fixtures/Question.json index fd29115c..0134835a 100644 --- a/edivorce/fixtures/Question.json +++ b/edivorce/fixtures/Question.json @@ -492,7 +492,9 @@ "name": "You and your spouse are asking for an order for spousal support as follows", "description": "For step 6, Form 1 5. Spousal support", "summary_order": 47, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_spousal_support_orders_wanted", + "reveal_response": "True" }, "model": "core.question", "pk": "spouse_support_details" @@ -502,7 +504,9 @@ "name": "Please indicate which act you are asking for support under.", "description": "For step 6, Form 1 5. Spousal support", "summary_order": 48, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_spousal_support_orders_wanted", + "reveal_response": "True" }, "model": "core.question", "pk": "spouse_support_act" @@ -512,7 +516,9 @@ "name": "Your children", "description": "For Step 6, Your children - Children details", "summary_order": 49, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "True" }, "model": "core.question", "pk": "claimant_children" @@ -522,7 +528,9 @@ "name": "How will you and your spouse be determining your income?", "description": "For Step 6, Your children - Income & expenses", "summary_order": 50, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "True" }, "model": "core.question", "pk": "how_will_calculate_income" @@ -532,7 +540,9 @@ "name": "What is your annual gross income as determined above?", "description": "For Step 6, Your children - Income & expenses", "summary_order": 51, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "True" }, "model": "core.question", "pk": "annual_gross_income" @@ -542,7 +552,9 @@ "name": "What is your spouse's annual gross income as determined above?", "description": "For Step 6, Your children - Income & expenses", "summary_order": 52, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "True" }, "model": "core.question", "pk": "spouse_annual_gross_income" @@ -564,7 +576,9 @@ "name": "Are you claiming any special and extraordinary expenses?", "description": "For Step 6, Your children - Income & expenses", "summary_order": 54, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "True" }, "model": "core.question", "pk": "special_extraordinary_expenses" @@ -778,7 +792,9 @@ "name": "Who is the payor?", "description": "For Step 6, Your children - Payor & fact sheets", "summary_order": 74, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "True" }, "model": "core.question", "pk": "child_support_payor" @@ -938,7 +954,9 @@ "name": "Are you or your spouse claiming undue hardship?", "description": "For Step 6, Your children - Payor & fact sheets - Fact Sheet E - Undue hardship", "summary_order": 88, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "True" }, "model": "core.question", "pk": "claiming_undue_hardship" @@ -1210,7 +1228,9 @@ "name": "Is medical coverage available for the children?", "description": "For Step 6, Your children - Payor & medical expenses", "summary_order": 112, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "True" }, "model": "core.question", "pk": "medical_coverage_available" @@ -1232,7 +1252,9 @@ "name": "Are there any child support payments (in arrears) that have not been paid (as of today's date) under an existing order or written agreement?", "description": "For Step 6, Your children - Payor & medical expenses", "summary_order": 114, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "True" }, "model": "core.question", "pk": "child_support_payments_in_arrears" @@ -1254,7 +1276,9 @@ "name": "What is the monthly child support amount proposed in the order to be paid by", "description": "For Step 6, Your children - What are you asking for", "summary_order": 116, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "True" }, "model": "core.question", "pk": "child_support_in_order" @@ -1312,7 +1336,9 @@ "name": "Do you have a separation agreement that sets out what you've agreed to around parenting and child support?", "description": "For Step 6, Your children - What are you asking for", "summary_order": 121, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "True" }, "model": "core.question", "pk": "have_separation_agreement" @@ -1322,7 +1348,9 @@ "name": "Do you have an order about support of the children?", "description": "For Step 6, Your children - What are you asking for", "summary_order": 122, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "YES" }, "model": "core.question", "pk": "have_court_order" @@ -1332,7 +1360,9 @@ "name": "The court needs to know what the current parenting arrangements are for the children of the marriage. Please describe below.", "description": "For Step 6, Your children - What are you asking for", "summary_order": 123, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "True" }, "model": "core.question", "pk": "what_parenting_arrangements" @@ -1342,7 +1372,9 @@ "name": "Are you asking the court for an order about parenting arrangements or contact with a child?", "description": "For Step 6, Your children - What are you asking for", "summary_order": 124, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_has_children_of_marriage", + "reveal_response": "True" }, "model": "core.question", "pk": "want_parenting_arrangements" @@ -1388,7 +1420,9 @@ "name": "How have you and your spouse agreed to deal with your property and debt?", "description": "For step 7, Form 1 6. Property and debt", "summary_order": 128, - "required": "Required" + "required": "Conditional", + "conditional_target": "determine_property_debt_orders_wanted", + "reveal_response": "True" }, "model": "core.question", "pk": "deal_with_property_debt" @@ -1415,11 +1449,59 @@ "model": "core.question", "pk": "other_property_claims" }, +{ + "fields": { + "name": "Are you asking for a name change?", + "description": "For Step 10, Forms 38 and 52's Orders sections", + "summary_order": 131, + "required": "Conditional", + "conditional_target": "determine_other_orders_wanted", + "reveal_response": "True" + }, + "model": "core.question", + "pk": "name_change_you" +}, +{ + "fields": { + "name": "Please enter the full name", + "description": "For Step 10, Forms 38 and 52's Orders sections", + "summary_order": 132, + "required": "Conditional", + "conditional_target": "name_change_you", + "reveal_response": "YES" + }, + "model": "core.question", + "pk": "name_change_you_fullname" +}, +{ + "fields": { + "name": "Is your spouse asking for a name change?", + "description": "For Step 10, Forms 38 and 52's Orders sections", + "summary_order": 133, + "required": "Conditional", + "conditional_target": "determine_other_orders_wanted", + "reveal_response": "True" + }, + "model": "core.question", + "pk": "name_change_spouse" +}, +{ + "fields": { + "name": "Please enter the full name", + "description": "For Step 10, Forms 38 and 52's Orders sections", + "summary_order": 134, + "required": "Conditional", + "conditional_target": "name_change_spouse", + "reveal_response": "YES" + }, + "model": "core.question", + "pk": "name_change_spouse_fullname" +}, { "fields": { "name": "Please enter the details for any other orders that you are asking for.", "description": "For step 8 other orders, Form 1 7. Other", - "summary_order": 131, + "summary_order": 135, "required": "" }, "model": "core.question", @@ -1429,7 +1511,7 @@ "fields": { "name": "What is the best address to send you official court documents?", "description": "For step 9, Form 1 8. Claimants' addresses for service, Form 38(joint) Affidavit section", - "summary_order": 132, + "summary_order": 136, "required": "Required" }, "model": "core.question", @@ -1439,7 +1521,7 @@ "fields": { "name": "City", "description": "For step 9, Form 1 8. Claimants' addresses for service, Form 38(joint) Affidavit section", - "summary_order": 133, + "summary_order": 137, "required": "Required" }, "model": "core.question", @@ -1449,7 +1531,7 @@ "fields": { "name": "Prov", "description": "For step 9, Form 1 8. Claimants' addresses for service, Form 38(joint) Affidavit section", - "summary_order": 134, + "summary_order": 138, "required": "" }, "model": "core.question", @@ -1459,7 +1541,7 @@ "fields": { "name": "Country", "description": "For step 9, Form 1 8. Claimants' addresses for service, Form 38(joint) Affidavit section", - "summary_order": 135, + "summary_order": 139, "required": "Required" }, "model": "core.question", @@ -1469,7 +1551,7 @@ "fields": { "name": "Other Country", "description": "For step 9, Form 1 8. Claimants' addresses for service, Form 38(joint) Affidavit section", - "summary_order": 136, + "summary_order": 140, "required": "Conditional", "conditional_target": "address_to_send_official_document_country_you", "reveal_response": "Other" @@ -1481,7 +1563,7 @@ "fields": { "name": "Postal code", "description": "For step 9, Form 1 8. Claimants' addresses for service, Form 38(joint) Affidavit section", - "summary_order": 137, + "summary_order": 141, "required": "" }, "model": "core.question", @@ -1491,7 +1573,7 @@ "fields": { "name": "Fax number", "description": "For step 9, Form 1 8. Claimants' addresses for service", - "summary_order": 138, + "summary_order": 142, "required": "" }, "model": "core.question", @@ -1501,7 +1583,7 @@ "fields": { "name": "Email", "description": "For step 9, Form 1 8. Claimants' addresses for service", - "summary_order": 139, + "summary_order": 143, "required": "" }, "model": "core.question", @@ -1511,7 +1593,7 @@ "fields": { "name": "What is the best address to send your spouse official court documents?", "description": "For step 9, Form 1 8. Claimants' addresses for service, Form 38(joint) Affidavit section", - "summary_order": 140, + "summary_order": 144, "required": "Required" }, "model": "core.question", @@ -1521,7 +1603,7 @@ "fields": { "name": "City", "description": "For step 9, Form 1 8. Claimants' addresses for service, Form 38(joint) Affidavit section", - "summary_order": 141, + "summary_order": 145, "required": "Required" }, "model": "core.question", @@ -1531,7 +1613,7 @@ "fields": { "name": "Prov", "description": "For step 9, Form 1 8. Claimants' addresses for service, Form 38(joint) Affidavit section", - "summary_order": 142, + "summary_order": 146, "required": "" }, "model": "core.question", @@ -1541,7 +1623,7 @@ "fields": { "name": "Country", "description": "For step 9, Form 1 8. Claimants' addresses for service, Form 38(joint) Affidavit section", - "summary_order": 143, + "summary_order": 147, "required": "Required" }, "model": "core.question", @@ -1551,7 +1633,7 @@ "fields": { "name": "Other Country", "description": "For step 9, Form 1 8. Claimants' addresses for service, Form 38(joint) Affidavit section", - "summary_order": 144, + "summary_order": 148, "required": "Conditional", "conditional_target": "address_to_send_official_document_country_spouse", "reveal_response": "Other" @@ -1563,7 +1645,7 @@ "fields": { "name": "Postal code", "description": "For step 9, Form 1 8. Claimants' addresses for service", - "summary_order": 145, + "summary_order": 149, "required": "" }, "model": "core.question", @@ -1573,7 +1655,7 @@ "fields": { "name": "Fax number", "description": "For step 9, Form 1 8. Claimants' addresses for service", - "summary_order": 146, + "summary_order": 150, "required": "" }, "model": "core.question", @@ -1583,7 +1665,7 @@ "fields": { "name": "Email", "description": "For step 9, Form 1 8. Claimants' addresses for service", - "summary_order": 147, + "summary_order": 151, "required": "" }, "model": "core.question", @@ -1593,7 +1675,7 @@ "fields": { "name": "Divorce is to take effect on", "description": "For step 9, Form 52 This Court Orders that", - "summary_order": 148, + "summary_order": 152, "required": "Required" }, "model": "core.question", @@ -1603,7 +1685,7 @@ "fields": { "name": "Divorce is to take effect on specific date", "description": "For step 9 - specific date, Form 52 This Court Orders that", - "summary_order": 149, + "summary_order": 153, "required": "Conditional", "conditional_target": "divorce_take_effect_on", "reveal_response": "specific date" @@ -1615,56 +1697,12 @@ "fields": { "name": "Where will you be filing for divorce?", "description": "For step 10, Form 1 court registry, Form 35 court registry, Form 36 court registry, Form 38(joint and sole) court registry, Form 52 court registry", - "summary_order": 150, + "summary_order": 154, "required": "Required" }, "model": "core.question", "pk": "court_registry_for_filing" }, -{ - "fields": { - "name": "Are you asking for a name change?", - "description": "For Step 10, Forms 38 and 52's Orders sections", - "summary_order": 151, - "required": "Required" - }, - "model": "core.question", - "pk": "name_change_you" -}, -{ - "fields": { - "name": "Please enter the full name", - "description": "For Step 10, Forms 38 and 52's Orders sections", - "summary_order": 152, - "required": "Conditional", - "conditional_target": "name_change_you", - "reveal_response": "YES" - }, - "model": "core.question", - "pk": "name_change_you_fullname" -}, -{ - "fields": { - "name": "Is your spouse asking for a name change?", - "description": "For Step 10, Forms 38 and 52's Orders sections", - "summary_order": 153, - "required": "Required" - }, - "model": "core.question", - "pk": "name_change_spouse" -}, -{ - "fields": { - "name": "Please enter the full name", - "description": "For Step 10, Forms 38 and 52's Orders sections", - "summary_order": 154, - "required": "Conditional", - "conditional_target": "name_change_spouse", - "reveal_response": "YES" - }, - "model": "core.question", - "pk": "name_change_spouse_fullname" -}, { "fields": { "name": "Select how you would like to swear/affirm your affidavit(s)?",