diff --git a/edivorce/apps/core/static/js/main.js b/edivorce/apps/core/static/js/main.js index b7f5c5f6..425bed48 100755 --- a/edivorce/apps/core/static/js/main.js +++ b/edivorce/apps/core/static/js/main.js @@ -53,6 +53,7 @@ $(function () { // so any listener attached to target element are notified that // contents have changed. $('[data-mirror="true"]').on('change', mirrorOnChange); + $('[data-mirror_on_pressed="true"]').on('keyup', mirrorOnChange); // All of the input fields in the row will be saved as a single object diff --git a/edivorce/apps/core/templates/question/06_children_income_expenses.html b/edivorce/apps/core/templates/question/06_children_income_expenses.html index 2ef368b8..91624036 100644 --- a/edivorce/apps/core/templates/question/06_children_income_expenses.html +++ b/edivorce/apps/core/templates/question/06_children_income_expenses.html @@ -424,12 +424,12 @@
- {% money_input_field name="child_care_expenses" id="child_care_expenses_month" class="fact-sheet-input money extraordinary-expense-monthly" data_sum="true" data_sum_class="extraordinary-expense-monthly" data_sum_target_id="total_extraordinary_expense_monthly" data_mirror="true" data_mirror_target="#child_care_expenses_year" data_mirror_scale="year_up" %} + {% money_input_field name="child_care_expenses" id="child_care_expenses_month" class="fact-sheet-input money extraordinary-expense-monthly" data_mirror_on_pressed="true" data_mirror_target="#child_care_expenses_year" data_mirror_scale="year_up" data_mirror_broadcast_change="true" scale_to_monthly="true" %}
- {% money_input_field value_src="child_care_expenses" id="child_care_expenses_year" class="fact-sheet-input money extraordinary_expense_annually" scale_factor="12" data_mirror="true" data_mirror_target="#child_care_expenses_month" data_mirror_scale="month_down" data_mirror_broadcast_change="true" %} + {% money_input_field name="annual_child_care_expenses" id="child_care_expenses_year" class="fact-sheet-input money extraordinary-expense-annually" data_mirror_on_pressed="true" data_mirror_target="#child_care_expenses_month" data_mirror_scale="month_down" data_mirror_broadcast_change="true" data_sum="true" data_sum_class="extraordinary-expense-annually" data_sum_target_id="total_extraordinary_expense_annually" %}
@@ -439,12 +439,12 @@
- {% money_input_field name="children_healthcare_premiums" id="children_healthcare_premiums_month" class="fact-sheet-input money extraordinary-expense-monthly" data_sum="true" data_sum_class="extraordinary-expense-monthly" data_sum_target_id="total_extraordinary_expense_monthly" data_mirror="true" data_mirror_target="#children_healthcare_premiums_year" data_mirror_scale="year_up" %} + {% money_input_field name="children_healthcare_premiums" id="children_healthcare_premiums_month" class="fact-sheet-input money extraordinary-expense-monthly" data_mirror_on_pressed="true" data_mirror_target="#children_healthcare_premiums_year" data_mirror_scale="year_up" scale_to_monthly="true" data_mirror_broadcast_change="true" %}
- {% money_input_field value_src="children_healthcare_premiums" id="children_healthcare_premiums_year" class="fact-sheet-input money extraordinary_expense_annually" scale_factor="12" data_mirror="true" data_mirror_target="#children_healthcare_premiums_month" data_mirror_scale="month_down" data_mirror_broadcast_change="true" %} + {% money_input_field name="annual_children_healthcare_premiums" id="children_healthcare_premiums_year" class="fact-sheet-input money extraordinary-expense-annually" data_mirror_on_pressed="true" data_mirror_target="#children_healthcare_premiums_month" data_mirror_scale="month_down" data_mirror_broadcast_change="true" data_sum="true" data_sum_class="extraordinary-expense-annually" data_sum_target_id="total_extraordinary_expense_annually" %}
@@ -464,12 +464,12 @@
- {% money_input_field name="health_related_expenses" id="health_related_expenses_month" class="fact-sheet-input money extraordinary-expense-monthly" data_sum="true" data_sum_class="extraordinary-expense-monthly" data_sum_target_id="total_extraordinary_expense_monthly" data_mirror="true" data_mirror_target="#health_related_expenses_year" data_mirror_scale="year_up" %} + {% money_input_field name="health_related_expenses" id="health_related_expenses_month" class="fact-sheet-input money extraordinary-expense-monthly" data_mirror_on_pressed="true" data_mirror_target="#health_related_expenses_year" data_mirror_scale="year_up" scale_to_monthly="true" data_mirror_broadcast_change="true" %}
- {% money_input_field value_src="health_related_expenses" id="health_related_expenses_year" class="fact-sheet-input money extraordinary_expense_annually" scale_factor="12" data_mirror="true" data_mirror_target="#health_related_expenses_month" data_mirror_scale="month_down" data_mirror_broadcast_change="true" %} + {% money_input_field name="annual_health_related_expenses" id="health_related_expenses_year" class="fact-sheet-input money extraordinary-expense-annually" data_mirror_on_pressed="true" data_mirror_target="#health_related_expenses_month" data_mirror_scale="month_down" data_mirror_broadcast_change="true" data_sum="true" data_sum_class="extraordinary-expense-annually" data_sum_target_id="total_extraordinary_expense_annually" %}
@@ -489,12 +489,12 @@
- {% money_input_field name="extraordinary_educational_expenses" id="extraordinary_educational_expenses_month" class="fact-sheet-input money extraordinary-expense-monthly" data_sum="true" data_sum_class="extraordinary-expense-monthly" data_sum_target_id="total_extraordinary_expense_monthly" data_mirror="true" data_mirror_target="#extraordinary_educational_expenses_year" data_mirror_scale="year_up" %} + {% money_input_field name="extraordinary_educational_expenses" id="extraordinary_educational_expenses_month" class="fact-sheet-input money extraordinary-expense-monthly" data_mirror_on_pressed="true" data_mirror_target="#extraordinary_educational_expenses_year" data_mirror_scale="year_up" scale_to_monthly="true" data_mirror_broadcast_change="true" %}
- {% money_input_field value_src="extraordinary_educational_expenses" id="extraordinary_educational_expenses_year" class="fact-sheet-input money extraordinary_expense_annually" scale_factor="12" data_mirror="true" data_mirror_target="#extraordinary_educational_expenses_month" data_mirror_scale="month_down" data_mirror_broadcast_change="true" %} + {% money_input_field name="annual_extraordinary_educational_expenses" id="extraordinary_educational_expenses_year" class="fact-sheet-input money extraordinary-expense-annually" data_mirror_on_pressed="true" data_mirror_target="#extraordinary_educational_expenses_month" data_mirror_scale="month_down" data_mirror_broadcast_change="true" data_sum="true" data_sum_class="extraordinary-expense-annually" data_sum_target_id="total_extraordinary_expense_annually" %}
@@ -503,12 +503,12 @@ Post-secondary school expenses
- {% money_input_field name="post_secondary_expenses" id="post_secondary_expenses_month" class="fact-sheet-input extraordinary-expense-monthly" data_sum="true" data_sum_class="extraordinary-expense-monthly" data_sum_target_id="total_extraordinary_expense_monthly" data_mirror="true" data_mirror_target="#post_secondary_expenses_year" data_mirror_scale="year_up" %} + {% money_input_field name="post_secondary_expenses" id="post_secondary_expenses_month" class="fact-sheet-input extraordinary-expense-monthly" data_mirror_on_pressed="true" data_mirror_target="#post_secondary_expenses_year" data_mirror_scale="year_up" scale_to_monthly="true" data_mirror_broadcast_change="true" %}
- {% money_input_field value_src="post_secondary_expenses" id="post_secondary_expenses_year" class="fact-sheet-input money extraordinary_expense_annually" scale_factor="12" data_mirror="true" data_mirror_target="#post_secondary_expenses_month" data_mirror_scale="month_down" data_mirror_broadcast_change="true" %} + {% money_input_field name="annual_post_secondary_expenses" id="post_secondary_expenses_year" class="fact-sheet-input money extraordinary-expense-annually" data_mirror_on_pressed="true" data_mirror_target="#post_secondary_expenses_month" data_mirror_scale="month_down" data_mirror_broadcast_change="true" data_sum="true" data_sum_class="extraordinary-expense-annually" data_sum_target_id="total_extraordinary_expense_annually" %}
@@ -530,12 +530,12 @@
- {% money_input_field name="extraordinary_extracurricular_expenses" id="extraordinary_extracurricular_expenses_month" class="fact-sheet-input money extraordinary-expense-monthly" data_sum="true" data_sum_class="extraordinary-expense-monthly" data_sum_target_id="total_extraordinary_expense_monthly" data_mirror="true" data_mirror_target="#extraordinary_extracurricular_expenses_year" data_mirror_scale="year_up" %} + {% money_input_field name="extraordinary_extracurricular_expenses" id="extraordinary_extracurricular_expenses_month" class="fact-sheet-input money extraordinary-expense-monthly" data_mirror_on_pressed="true" data_mirror_target="#extraordinary_extracurricular_expenses_year" data_mirror_scale="year_up" scale_to_monthly="true" data_mirror_broadcast_change="true" %}
- {% money_input_field value_src="extraordinary_extracurricular_expenses" id="extraordinary_extracurricular_expenses_year" class="fact-sheet-input money extraordinary_expense_annually" scale_factor="12" data_mirror="true" data_mirror_target="#extraordinary_extracurricular_expenses_month" data_mirror_scale="month_down" data_mirror_broadcast_change="true" %} + {% money_input_field name="annual_extraordinary_extracurricular_expenses" id="extraordinary_extracurricular_expenses_year" class="fact-sheet-input money extraordinary-expense-annually" data_mirror_on_pressed="true" data_mirror_target="#extraordinary_extracurricular_expenses_month" data_mirror_scale="month_down" data_mirror_broadcast_change="true" data_sum="true" data_sum_class="extraordinary-expense-annually" data_sum_target_id="total_extraordinary_expense_annually" %}
@@ -544,13 +544,13 @@ Total section 7 expenses
- {% money_input_field name="total_section_seven_expenses" id="total_extraordinary_expense_monthly" class="fact-sheet-input money " readonly="" data_mirror="true" data_mirror_target="#total_extraordinary_expense_annually" data_mirror_scale="year_up" %} + {% money_input_field name="total_section_seven_expenses" id="total_extraordinary_expense_monthly" class="fact-sheet-input money " readonly="" scale_to_monthly="true" %}
- {% money_input_field value_src="total_section_seven_expenses" id="total_extraordinary_expense_annually" class="fact-sheet-input money " scale_factor="12" readonly="" %} + {% money_input_field name="annual_total_section_seven_expenses" id="total_extraordinary_expense_annually" class="fact-sheet-input money " readonly="" data_mirror="true" data_mirror_target="#total_extraordinary_expense_monthly" data_mirror_scale="month_down" data_mirror_broadcast_change="true" %}
diff --git a/edivorce/apps/core/templatetags/input_field.py b/edivorce/apps/core/templatetags/input_field.py index 46f9e005..8db9497d 100644 --- a/edivorce/apps/core/templatetags/input_field.py +++ b/edivorce/apps/core/templatetags/input_field.py @@ -1,4 +1,5 @@ from datetime import datetime +from decimal import Decimal, ROUND_HALF_UP import json from django import template @@ -9,7 +10,7 @@ register = template.Library() @register.simple_tag(takes_context=True) -def money_input_field(context, input_type='number', name='', value_src=None, value='', scale_factor=None, **kwargs): +def money_input_field(context, input_type='number', name='', value_src=None, value='', scale_factor=None, scale_to_monthly=None, **kwargs): """ :param context: @@ -31,6 +32,8 @@ def money_input_field(context, input_type='number', name='', value_src=None, val if scale_factor: value = float(value) * float(scale_factor) + if scale_to_monthly: + value = Decimal(float(value) / 12).quantize(Decimal('.01'), rounding=ROUND_HALF_UP) step = '0.01' if kwargs.get('step', None): diff --git a/edivorce/apps/core/utils/derived.py b/edivorce/apps/core/utils/derived.py index f513f769..94efc233 100644 --- a/edivorce/apps/core/utils/derived.py +++ b/edivorce/apps/core/utils/derived.py @@ -239,7 +239,7 @@ def annual_child_care_expenses(responses, derived): """ Return the annual cost of the monthly cost of child care expense """ try: - return 12 * float(responses.get('child_care_expenses', 0)) + return float(responses.get('annual_child_care_expenses', 0)) except ValueError: return 0 @@ -248,7 +248,7 @@ def annual_children_healthcare_premiums(responses, derived): """ Return the annual cost of the monthly cost of child health care premiums """ try: - return 12 * float(responses.get('children_healthcare_premiums', 0)) + return float(responses.get('annual_children_healthcare_premiums', 0)) except ValueError: return 0 @@ -257,7 +257,7 @@ def annual_health_related_expenses(responses, derived): """ Return the annual cost of the monthly cost of health related expense """ try: - return 12 * float(responses.get('health_related_expenses', 0)) + return float(responses.get('annual_health_related_expenses', 0)) except ValueError: return 0 @@ -266,7 +266,7 @@ def annual_extraordinary_educational_expenses(responses, derived): """ Return the annual cost of the monthly cost of educational expense """ try: - return 12 * float(responses.get('extraordinary_educational_expenses', 0)) + return float(responses.get('annual_extraordinary_educational_expenses', 0)) except ValueError: return 0 @@ -275,7 +275,7 @@ def annual_post_secondary_expenses(responses, derived): """ Return the annual cost of the monthly cost of post secondary expense """ try: - return 12 * float(responses.get('post_secondary_expenses', 0)) + return float(responses.get('annual_post_secondary_expenses', 0)) except ValueError: return 0 @@ -284,7 +284,7 @@ def annual_extraordinary_extracurricular_expenses(responses, derived): """ Return the annual cost of the monthly cost of education expense """ try: - return 12 * float(responses.get('extraordinary_extracurricular_expenses', 0)) + return float(responses.get('annual_extraordinary_extracurricular_expenses', 0)) except ValueError: return 0 @@ -311,7 +311,10 @@ def payor_section_seven_expenses(responses, derived): def annual_total_section_seven_expenses(responses, derived): """ Return the annual cost of the monthly cost of section 7 expense """ - return 12 * derived['total_section_seven_expenses'] + try: + return float(responses.get('annual_total_section_seven_expenses', 0)) + except ValueError: + return 0 def total_gross_income(responses, derived): diff --git a/edivorce/fixtures/Question.json b/edivorce/fixtures/Question.json index 1bdcec2b..fa1cd517 100644 --- a/edivorce/fixtures/Question.json +++ b/edivorce/fixtures/Question.json @@ -1195,6 +1195,16 @@ "model": "core.question", "pk": "child_care_expenses" }, +{ + "fields": { + "name": "Annual child care expenses for when the recipient works or goes to school", + "description": "For Step 6, Your children - Income & expenses - Spouse Fact Sheet F", + "summary_order": 0, + "required": "Conditional" + }, + "model": "core.question", + "pk": "annual_child_care_expenses" +}, { "fields": { "name": "Any healthcare premiums you pay to your employer or other provider to provide the coverage to your children rather than yourself", @@ -1207,6 +1217,18 @@ "model": "core.question", "pk": "children_healthcare_premiums" }, +{ + "fields": { + "name": "Any annual healthcare premiums you pay to your employer or other provider to provide the coverage to your children rather than yourself", + "description": "For Step 6, Your children - Income & expenses - Spouse Fact Sheet F", + "summary_order": 0, + "required": "Conditional", + "conditional_target": "special_extraordinary_expenses", + "reveal_response": "" + }, + "model": "core.question", + "pk": "annual_children_healthcare_premiums" +}, { "fields": { "name": "Health related expenses that exceed insurance reimbursement by at least $100", @@ -1219,6 +1241,18 @@ "model": "core.question", "pk": "health_related_expenses" }, +{ + "fields": { + "name": "Annual health related expenses that exceed insurance reimbursement by at least $100", + "description": "For Step 6, Your children - Income & expenses - Spouse Fact Sheet F", + "summary_order": 0, + "required": "Conditional", + "conditional_target": "special_extraordinary_expenses", + "reveal_response": "" + }, + "model": "core.question", + "pk": "annual_health_related_expenses" +}, { "fields": { "name": "Extraordinary primary, secondary or other educational expenses", @@ -1231,6 +1265,18 @@ "model": "core.question", "pk": "extraordinary_educational_expenses" }, +{ + "fields": { + "name": "Annual extraordinary primary, secondary or other educational expenses", + "description": "For Step 6, Your children - Income & expenses - Spouse Fact Sheet F", + "summary_order": 0, + "required": "Conditional", + "conditional_target": "special_extraordinary_expenses", + "reveal_response": "" + }, + "model": "core.question", + "pk": "annual_extraordinary_educational_expenses" +}, { "fields": { "name": "Post-secondary school expenses", @@ -1243,6 +1289,18 @@ "model": "core.question", "pk": "post_secondary_expenses" }, +{ + "fields": { + "name": "Annual Post-secondary school expenses", + "description": "For Step 6, Your children - Income & expenses - Spouse Fact Sheet F", + "summary_order": 0, + "required": "Conditional", + "conditional_target": "special_extraordinary_expenses", + "reveal_response": "" + }, + "model": "core.question", + "pk": "annual_post_secondary_expenses" +}, { "fields": { "name": "Extraordinary extracurricular activities expenses", @@ -1255,6 +1313,18 @@ "model": "core.question", "pk": "extraordinary_extracurricular_expenses" }, +{ + "fields": { + "name": "Annual extraordinary extracurricular activities expenses", + "description": "For Step 6, Your children - Income & expenses - Spouse Fact Sheet F", + "summary_order": 0, + "required": "Conditional", + "conditional_target": "special_extraordinary_expenses", + "reveal_response": "" + }, + "model": "core.question", + "pk": "annual_extraordinary_extracurricular_expenses" +}, { "fields": { "name": "Total section 7 expenses", @@ -1267,6 +1337,18 @@ "model": "core.question", "pk": "total_section_seven_expenses" }, +{ + "fields": { + "name": "Annual total section 7 expenses", + "description": "For Step 6, Your children - Income & expenses - Spouse Fact Sheet F", + "summary_order": 0, + "required": "Conditional", + "conditional_target": "special_extraordinary_expenses", + "reveal_response": "" + }, + "model": "core.question", + "pk": "annual_total_section_seven_expenses" +}, { "fields": { "name": "Your proportionate share",