From daa931228de15b2e697310b945bd4576a7bdc882 Mon Sep 17 00:00:00 2001 From: Brittain Hard Date: Fri, 1 Sep 2017 13:46:03 -0500 Subject: [PATCH 1/2] Add summary row. --- webapp/apps/taxbrain/views.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/webapp/apps/taxbrain/views.py b/webapp/apps/taxbrain/views.py index 15273d40..8da549aa 100644 --- a/webapp/apps/taxbrain/views.py +++ b/webapp/apps/taxbrain/views.py @@ -481,6 +481,25 @@ def edit_personal_results(request, pk): return render(request, 'taxbrain/input_form.html', init_context) +def add_summary_column(table): + import copy + summary = copy.deepcopy(table["cols"][-1]) + summary["label"] = "Summary" + table["cols"].append(summary) + table["col_labels"].append("Summary") + for x in table["rows"]: + row_total = 0 + for y in x["cells"]: + row_total += float(y["value"]) + x["cells"].append({ + 'format': {u'decimals': 1, u'divisor': 1000000000}, + u'value': unicode(row_total), + u'year_values': {} + }) + return table + + + def get_result_context(model, request, url): output = model.tax_result first_year = model.first_year @@ -528,9 +547,9 @@ def get_result_context(model, request, url): is_registered = True if request.user.is_authenticated() else False else: is_registered = False - tables['fiscal_change'] = tables['fiscal_tot_diffs'] - tables['fiscal_currentlaw'] = tables['fiscal_tot_base'] - tables['fiscal_reform'] = tables['fiscal_tot_ref'] + tables['fiscal_change'] = add_summary_column(tables['fiscal_tot_diffs']) + tables['fiscal_currentlaw'] = add_summary_column(tables['fiscal_tot_base']) + tables['fiscal_reform'] = add_summary_column(tables['fiscal_tot_ref']) json_table = json.dumps(tables) context = { From 34fee15e2fb9367ae427d4fdc4ebbb29ca8650b1 Mon Sep 17 00:00:00 2001 From: Brittain Hard Date: Fri, 1 Sep 2017 14:09:37 -0500 Subject: [PATCH 2/2] Change "Summary" to "Total" --- webapp/apps/taxbrain/views.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/webapp/apps/taxbrain/views.py b/webapp/apps/taxbrain/views.py index 8da549aa..505422e1 100644 --- a/webapp/apps/taxbrain/views.py +++ b/webapp/apps/taxbrain/views.py @@ -484,15 +484,18 @@ def edit_personal_results(request, pk): def add_summary_column(table): import copy summary = copy.deepcopy(table["cols"][-1]) - summary["label"] = "Summary" + summary["label"] = "Total" table["cols"].append(summary) - table["col_labels"].append("Summary") + table["col_labels"].append("Total") for x in table["rows"]: row_total = 0 for y in x["cells"]: row_total += float(y["value"]) x["cells"].append({ - 'format': {u'decimals': 1, u'divisor': 1000000000}, + 'format': { + u'decimals': 1, + u'divisor': 1000000000 + }, u'value': unicode(row_total), u'year_values': {} })