From dc74d2e61d02d75069f9f992f29ab4d3c7d8cf73 Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Tue, 24 Dec 2024 11:58:53 -0300 Subject: [PATCH] feat(yearly:currency): add percentage bar and refactor design --- app/apps/yearly_overview/views.py | 15 +- .../fragments/currency_data.html | 394 +++++++++--------- 2 files changed, 200 insertions(+), 209 deletions(-) diff --git a/app/apps/yearly_overview/views.py b/app/apps/yearly_overview/views.py index 5a09352..18e8166 100644 --- a/app/apps/yearly_overview/views.py +++ b/app/apps/yearly_overview/views.py @@ -80,23 +80,16 @@ def yearly_overview_by_currency(request, year: int): ) data = calculate_currency_totals(transactions) - - context = { - "income_current": remove_falsey_entries(data, "income_current"), - "income_projected": remove_falsey_entries(data, "income_projected"), - "expense_current": remove_falsey_entries(data, "expense_current"), - "expense_projected": remove_falsey_entries(data, "expense_projected"), - "total_current": remove_falsey_entries(data, "total_current"), - "total_final": remove_falsey_entries(data, "total_final"), - "total_projected": remove_falsey_entries(data, "total_projected"), - } + percentages = calculate_percentage_distribution(data) return render( request, "yearly_overview/fragments/currency_data.html", context={ "year": year, - "totals": context, + "totals": data, + "percentages": percentages, + "single": True if currency else False, }, ) diff --git a/app/templates/yearly_overview/fragments/currency_data.html b/app/templates/yearly_overview/fragments/currency_data.html index a0dddb2..ddee128 100644 --- a/app/templates/yearly_overview/fragments/currency_data.html +++ b/app/templates/yearly_overview/fragments/currency_data.html @@ -1,216 +1,214 @@ +{% load tools %} {% load month_name %} {% load i18n %} -
-
-
-
{% translate 'projected income' %}
-
-
-
- {% for entry in totals.income_projected.values %} -
- -
- {% if entry.exchanged and entry.exchanged.income_projected %} -
- -
+
+ {% for currency_id, currency in totals.items %} +
+ {% if not single %} +
+ {{ currency.currency.name }} ({{ currency.currency.code }}) +
{% endif %} - {% empty %} -
-
- {% endfor %} -
-
-
-
-
{% translate 'projected expenses' %}
-
-
-
- {% for entry in totals.expense_projected.values %} -
- -
- {% if entry.exchanged and entry.exchanged.expense_projected %} -
- +
+
+
{% translate 'projected income' %}
+
+
+
+ +
+ {% if currency.exchanged and currency.exchanged.income_projected %} +
+ +
{% endif %} - {% empty %} -
-
- {% endfor %} -
-
-
-
-
{% translate 'projected total' %}
-
-
-
- {% for entry in totals.total_projected.values %} -
- -
- {% if entry.exchanged and entry.exchanged.total_projected %} -
- +
+
+
{% translate 'projected expenses' %}
+
+
+
+
+ +
+
+ {% if currency.exchanged and currency.exchanged.expense_projected %} +
+ +
{% endif %} - {% empty %} -
-
- {% endfor %} -
-
-
-
-
-
{% translate 'current income' %}
-
-
-
- {% for entry in totals.income_current.values %} -
- -
- {% if entry.exchanged and entry.exchanged.income_current %} -
- +
+
+
{% translate 'projected total' %}
+
+
+
+ +
+ {% if currency.exchanged.total_projected and currency.exchanged.total_projected %} +
+ +
{% endif %} - {% empty %} -
-
- {% endfor %} -
-
-
-
-
{% translate 'current expenses' %}
-
-
-
- {% for entry in totals.expense_current.values %} -
- -
- {% if entry.exchanged and entry.exchanged.expense_current %} -
- +
+
+
+
{% translate 'current income' %}
+
+
+
+ +
+ {% if currency.exchanged and currency.exchanged.income_current %} +
+ +
{% endif %} - {% empty %} -
-
- {% endfor %} -
-
-
-
-
{% translate 'current total' %}
-
-
-
- {% for entry in totals.total_current.values %} -
- -
- {% if entry.exchanged and entry.exchanged.total_current %} -
- +
+
+
{% translate 'current expenses' %}
+
+
+
+ +
+ {% if currency.exchanged and currency.exchanged.expense_current %} +
+ +
{% endif %} - {% empty %} -
-
- {% endfor %} -
-
-
-
-
-
{% translate 'final total' %}
-
-
-
- {% for entry in totals.total_final.values %} -
- -
- {% if entry.exchanged and entry.exchanged.total_final %} -
- +
+
+
{% translate 'current total' %}
+
+
+
+ +
+ {% if currency.exchanged and currency.exchanged.total_current %} +
+ +
{% endif %} +
+
+
+
+
{% translate 'final total' %}
+
+
+
+ +
+
+ {% if currency.exchanged and currency.exchanged.total_final %} +
+ +
+ {% endif %} +
+ {% with p=percentages|get_dict_item:currency_id %} +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {% endwith %} {% empty %} -
-
- {% endfor %} +
-
+ {% endfor %}