From 7aedf524c6ea761a3fd6a4cbc4e736d5810adfa4 Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Sun, 13 Apr 2025 03:45:22 -0300 Subject: [PATCH] feat(insights:category-overview): add bar chart with category totals Closes #231 --- app/apps/insights/views.py | 6 +- .../fragments/category_overview/index.html | 278 ++++++++++++++---- 2 files changed, 220 insertions(+), 64 deletions(-) diff --git a/app/apps/insights/views.py b/app/apps/insights/views.py index f8ea555..1495d05 100644 --- a/app/apps/insights/views.py +++ b/app/apps/insights/views.py @@ -1,10 +1,8 @@ -import decimal -import json from collections import defaultdict from dateutil.relativedelta import relativedelta from django.contrib.auth.decorators import login_required -from django.db.models import Sum, Avg, F +from django.db.models import Sum from django.shortcuts import render from django.utils import timezone from django.views.decorators.http import require_http_methods @@ -22,13 +20,13 @@ from apps.insights.utils.category_explorer import ( get_category_sums_by_account, get_category_sums_by_currency, ) +from apps.insights.utils.category_overview import get_categories_totals from apps.insights.utils.sankey import ( generate_sankey_data_by_account, generate_sankey_data_by_currency, ) from apps.insights.utils.transactions import get_transactions from apps.transactions.models import TransactionCategory, Transaction -from apps.insights.utils.category_overview import get_categories_totals from apps.transactions.utils.calculations import calculate_currency_totals diff --git a/app/templates/insights/fragments/category_overview/index.html b/app/templates/insights/fragments/category_overview/index.html index d57465f..360b2f9 100644 --- a/app/templates/insights/fragments/category_overview/index.html +++ b/app/templates/insights/fragments/category_overview/index.html @@ -1,68 +1,226 @@ {% load i18n %} -
+
{% if total_table %} -
- - - - - - - - - - - {% for category in total_table.values %} +
+
{% trans 'Category' %}{% trans 'Income' %}{% trans 'Expense' %}{% trans 'Total' %}
+ - - - - + + + + - {% endfor %} - -
{% if category.name %}{{ category.name }}{% else %}{% trans 'Uncategorized' %}{% endif %} - {% for currency in category.currencies.values %} - {% if currency.total_income != 0 %} - - {% else %} -
-
- {% endif %} - {% endfor %} -
- {% for currency in category.currencies.values %} - {% if currency.total_expense != 0 %} - - {% else %} -
-
- {% endif %} - {% endfor %} -
- {% for currency in category.currencies.values %} - {% if currency.total_final != 0 %} - - {% else %} -
-
- {% endif %} - {% endfor %} -
{% trans 'Category' %}{% trans 'Income' %}{% trans 'Expense' %}{% trans 'Total' %}
-
+ + + {% for category in total_table.values %} + + {% if category.name %}{{ category.name }}{% else %}{% trans 'Uncategorized' %}{% endif %} + + {% for currency in category.currencies.values %} + {% if currency.total_income != 0 %} + + {% else %} +
-
+ {% endif %} + {% endfor %} + + + {% for currency in category.currencies.values %} + {% if currency.total_expense != 0 %} + + {% else %} +
-
+ {% endif %} + {% endfor %} + + + {% for currency in category.currencies.values %} + {% if currency.total_final != 0 %} + + {% else %} +
-
+ {% endif %} + {% endfor %} + + + {% endfor %} + + +
+ +
+
+ +
+
+ + {{ total_table|json_script:"categoryOverviewData" }} + + + {% else %} {% endif %}