diff --git a/edivorce/apps/core/utils/question_step_mapping.py b/edivorce/apps/core/utils/question_step_mapping.py index d0c1cb44..53a09e21 100644 --- a/edivorce/apps/core/utils/question_step_mapping.py +++ b/edivorce/apps/core/utils/question_step_mapping.py @@ -173,84 +173,6 @@ question_step_mapping = { 'filing_locations': ['court_registry_for_filing'], } -substep_mapping = { - 'your_children': ['claimant_children'], - '': ['how_will_calculate_income', - 'annual_gross_income', - 'spouse_annual_gross_income', - 'payor_monthly_child_support_amount', - 'special_extraordinary_expenses', - 'child_support_payor', - 'claiming_undue_hardship', - 'claimants_agree_to_child_support_amount', - 'medical_coverage_available', - 'whose_plan_is_coverage_under', - 'child_support_payments_in_arrears', - 'child_support_arrears_amount', - 'child_support_in_order', - 'order_monthly_child_support_amount', - 'child_support_in_order_reason', - 'child_support_payment_special_provisions', - 'number_children_seeking_support', - 'child_support_amount_under_high_income', - 'percent_income_over_high_income_limit', - 'amount_income_over_high_income_limit', - 'total_guideline_amount', - 'agree_to_child_support_amount', - 'agreed_child_support_amount', - 'reason_child_support_amount', - 'have_separation_agreement', - 'have_court_order', - 'what_parenting_arrangements', - 'want_parenting_arrangements', - 'order_respecting_arrangement', - 'order_for_child_support', - 'child_support_act', - 'spouse_number_children_seeking_support', - 'spouse_child_support_amount_under_high_income', - 'spouse_percent_income_over_high_income_limit', - 'spouse_amount_income_over_high_income_limit', - 'spouse_total_guideline_amount', - 'spouse_agree_to_child_support_amount', - 'spouse_agreed_child_support_amount', - 'spouse_reason_child_support_amount', - 'you_spouse_entered_agreement', - 'claimant_debts', - 'claimant_expenses', - 'supporting_non_dependents', - 'supporting_dependents', - 'supporting_disabled', - 'undue_hardship', - 'income_others', - 'total_income_others', - 'number_of_children', - 'time_spent_with_you', - 'time_spent_with_spouse', - 'annual_gross_income', - 'spouse_annual_gross_income', - 'your_child_support_paid_b', - 'your_spouse_child_support_paid_b', - 'your_child_support_paid_c', - 'your_spouse_child_support_paid_c', - 'extra_ordinary_expenses_you', - 'extra_ordinary_expenses_spouse', - 'additional_relevant_spouse_children_info', - 'difference_between_claimants', - 'child_care_expenses', - 'children_healthcare_premiums', - 'health_related_expenses', - 'extraordinary_educational_expenses', - 'post_secondary_expenses', - 'extraordinary_extracurricular_expenses', - 'total_section_seven_expenses', - 'your_proportionate_share_percent', - 'your_proportionate_share_amount', - 'spouse_proportionate_share_percent', - 'spouse_proportionate_share_amount', - 'describe_order_special_extra_expenses'] -} - - page_step_mapping = { 'orders': 'which_orders', 'claimant': 'your_information', diff --git a/edivorce/apps/core/utils/step_completeness.py b/edivorce/apps/core/utils/step_completeness.py index 9fe53380..af388074 100644 --- a/edivorce/apps/core/utils/step_completeness.py +++ b/edivorce/apps/core/utils/step_completeness.py @@ -34,15 +34,18 @@ def evaluate_numeric_condition(target, reveal_response): def get_step_status(responses_by_step): status_dict = {} + missing_response_dict = {} for step, lst in responses_by_step.items(): if not lst: status_dict[step] = "Not started" else: - if is_complete(step, lst)[0]: + complete, missing_responses = is_complete(step, lst) + if complete: status_dict[step] = "Complete" else: + missing_response_dict[step] = missing_responses status_dict[step] = "Started" - return status_dict + return status_dict, missing_response_dict def is_complete(step, lst): @@ -65,6 +68,21 @@ def is_complete(step, lst): if not __has_value(question_key, lst): complete = False missing_responses += [question_key] + elif question_key == "special_extraordinary_expenses": + has_extraordinary_expenses = __get_value("special_extraordinary_expenses", lst) + if has_extraordinary_expenses.lower() == 'yes': + # validate at least one item is > 0 + special_expenses_keys = ["child_care_expenses", "annual_child_care_expenses", "children_healthcare_premiums", + "annual_children_healthcare_premiums", "health_related_expenses", "annual_health_related_expenses", + "extraordinary_educational_expenses", "annual_extraordinary_educational_expenses", + "post_secondary_expenses", "annual_post_secondary_expenses", "extraordinary_extracurricular_expenses", + "annual_extraordinary_extracurricular_expenses"] + for expense in special_expenses_keys: + value = __get_value(expense, lst) + if value and float(value) > 0: + break + else: + missing_responses.append('special_extraordinary_expenses_details') for question in conditional_list: # check condition for payor_monthly_child_support_amount @@ -145,10 +163,12 @@ def __condition_met(reveal_response, target, lst): return False -def __has_value(key, lst): +def __get_value(key, lst): for user_response in lst: if user_response["question_id"] == key: - answer = user_response["value"] - if answer != "" and answer != "[]" and answer != '[["",""]]' and answer != "\n": - return True - return False + return user_response["value"] + + +def __has_value(key, lst): + value = __get_value(key, lst) + return value and value != "" and value != "[]" and value != '[["",""]]' and value != "\n" diff --git a/edivorce/apps/core/utils/user_response.py b/edivorce/apps/core/utils/user_response.py index 1026e02c..c1d9933f 100644 --- a/edivorce/apps/core/utils/user_response.py +++ b/edivorce/apps/core/utils/user_response.py @@ -1,10 +1,10 @@ from edivorce.apps.core.models import UserResponse, Question -from edivorce.apps.core.utils.question_step_mapping import question_step_mapping, substep_mapping +from edivorce.apps.core.utils.question_step_mapping import question_step_mapping from edivorce.apps.core.utils.step_completeness import evaluate_numeric_condition from collections import OrderedDict -def get_responses_from_db(bceid_user, show_errors=False, step=None, substep=None): +def get_responses_from_db(bceid_user): """ Get UserResponses from the database for a user.""" married, married_questions, responses = __get_data(bceid_user) responses_dict = {} @@ -13,23 +13,6 @@ def get_responses_from_db(bceid_user, show_errors=False, step=None, substep=None responses_dict[answer.question.key] = '' elif answer.value.strip('[').strip(']'): responses_dict[answer.question.key] = answer.value - if show_errors: - if substep: - step_questions = substep_mapping.get(substep, []) - else: - step_questions = question_step_mapping.get(step, []) - questions = Question.objects.filter(key__in=step_questions) - for question in questions: - if responses_dict.get(question.key): - error = False - elif question.required == 'Required': - error = True - elif question.required == 'Conditional': - conditional_response = UserResponse.objects.filter(question=question.conditional_target).first() - error = conditional_response and conditional_response.value == question.reveal_response - else: - error = False - responses_dict['{}_error'.format(question.key)] = error return responses_dict diff --git a/edivorce/apps/core/views/main.py b/edivorce/apps/core/views/main.py index 552c91ab..31c2b457 100644 --- a/edivorce/apps/core/views/main.py +++ b/edivorce/apps/core/views/main.py @@ -43,7 +43,8 @@ def prequalification(request, step): responses_dict = get_responses_from_db(request.user) responses_dict['active_page'] = 'prequalification' responses_by_step = get_responses_from_db_grouped_by_steps(request.user) - responses_dict['step_status'] = get_step_status(responses_by_step) + step_status, _ = get_step_status(responses_by_step) + responses_dict['step_status'] = step_status return render(request, template_name=template, context=responses_dict) @@ -156,7 +157,8 @@ def overview(request): responses_dict_by_step = get_responses_from_db_grouped_by_steps(request.user) # Add step status dictionary - responses_dict_by_step['step_status'] = get_step_status(responses_dict_by_step) + step_status, _ = get_step_status(responses_dict_by_step) + responses_dict_by_step['step_status'] = step_status responses_dict_by_step['active_page'] = 'overview' responses_dict_by_step['derived'] = get_derived_data(get_responses_from_db(request.user)) @@ -188,15 +190,18 @@ def question(request, step, sub_step=None): template = 'question/%02d_%s%s.html' % (template_step_order[step], step, sub_page_template) responses_dict_by_step = get_responses_from_db_grouped_by_steps(request.user, True) - step_status = get_step_status(responses_dict_by_step) + step_status, missing_questions = get_step_status(responses_dict_by_step) if step == "review": responses_dict = responses_dict_by_step derived = get_derived_data(get_responses_from_db(request.user)) else: question_step = page_step_mapping.get(step, step) show_errors = step_status.get(question_step) == 'Started' - responses_dict = get_responses_from_db(request.user, show_errors=show_errors, step=question_step, substep=sub_step) + responses_dict = get_responses_from_db(request.user) derived = get_derived_data(responses_dict) + if show_errors: + for key in missing_questions.get(question_step): + responses_dict[key + '_error'] = True # Add step status dictionary responses_dict['step_status'] = step_status