From 6947c6affd9a298fe7b4a901ae8d75adc05a9f75 Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Wed, 19 Feb 2025 23:07:28 -0300 Subject: [PATCH] feat(insights): add late and recent transactions --- app/apps/insights/urls.py | 10 +++ app/apps/insights/views.py | 30 +++++++- app/locale/de/LC_MESSAGES/django.po | 66 +++++++++++------ app/locale/nl/LC_MESSAGES/django.po | 74 +++++++++++++------ app/locale/pt_BR/LC_MESSAGES/django.po | 72 +++++++++++------- app/templates/cotton/msg/empty.html | 2 +- .../category_explorer/charts/currency.html | 2 +- .../insights/fragments/late_transactions.html | 18 +++++ .../fragments/latest_transactions.html | 16 ++++ app/templates/insights/pages/index.html | 14 +++- 10 files changed, 228 insertions(+), 76 deletions(-) create mode 100644 app/templates/insights/fragments/late_transactions.html create mode 100644 app/templates/insights/fragments/latest_transactions.html diff --git a/app/apps/insights/urls.py b/app/apps/insights/urls.py index bc0806b..2c09413 100644 --- a/app/apps/insights/urls.py +++ b/app/apps/insights/urls.py @@ -29,4 +29,14 @@ urlpatterns = [ views.category_sum_by_currency, name="category_sum_by_currency", ), + path( + "insights/late-transactions/", + views.late_transactions, + name="insights_late_transactions", + ), + path( + "insights/latest-transactions/", + views.latest_transactions, + name="insights_latest_transactions", + ), ] diff --git a/app/apps/insights/views.py b/app/apps/insights/views.py index c6738cc..3141873 100644 --- a/app/apps/insights/views.py +++ b/app/apps/insights/views.py @@ -22,7 +22,7 @@ from apps.insights.utils.sankey import ( generate_sankey_data_by_currency, ) from apps.insights.utils.transactions import get_transactions -from apps.transactions.models import TransactionCategory +from apps.transactions.models import TransactionCategory, Transaction @login_required @@ -157,3 +157,31 @@ def category_sum_by_currency(request): "insights/fragments/category_explorer/charts/currency.html", {"currency_data": currency_data}, ) + + +@only_htmx +@login_required +@require_http_methods(["GET"]) +def latest_transactions(request): + limit = timezone.now() - relativedelta(days=3) + transactions = Transaction.objects.filter(created_at__gte=limit)[:30] + + return render( + request, + "insights/fragments/latest_transactions.html", + {"transactions": transactions}, + ) + + +@only_htmx +@login_required +@require_http_methods(["GET"]) +def late_transactions(request): + now = timezone.localdate(timezone.now()) + transactions = Transaction.objects.filter(is_paid=False, date__lt=now) + + return render( + request, + "insights/fragments/late_transactions.html", + {"transactions": transactions}, + ) diff --git a/app/locale/de/LC_MESSAGES/django.po b/app/locale/de/LC_MESSAGES/django.po index 8b2e5c7..b1fbaaa 100644 --- a/app/locale/de/LC_MESSAGES/django.po +++ b/app/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-02-19 13:44-0300\n" +"POT-Creation-Date: 2025-02-19 23:05-0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -773,15 +773,15 @@ msgstr "" msgid "Please upload either a ZIP file or at least one CSV file" msgstr "" -#: apps/export_app/views.py:169 +#: apps/export_app/views.py:168 msgid "You have to select at least one export" msgstr "" -#: apps/export_app/views.py:187 +#: apps/export_app/views.py:186 msgid "Data restored successfully" msgstr "" -#: apps/export_app/views.py:199 +#: apps/export_app/views.py:198 msgid "" "There was an error restoring your data. Check the logs for more details." msgstr "" @@ -865,17 +865,17 @@ msgstr "" msgid "Uncategorized" msgstr "" -#: apps/insights/utils/category_explorer.py:70 -#: apps/insights/utils/category_explorer.py:153 +#: apps/insights/utils/category_explorer.py:66 +#: apps/insights/utils/category_explorer.py:145 #: templates/cotton/ui/percentage_distribution.html:10 #: templates/cotton/ui/percentage_distribution.html:14 -#: templates/insights/fragments/category_explorer/charts/account.html:60 -#: templates/insights/fragments/category_explorer/charts/currency.html:60 +#: templates/insights/fragments/category_explorer/charts/account.html:72 +#: templates/insights/fragments/category_explorer/charts/currency.html:72 msgid "Current Income" msgstr "" -#: apps/insights/utils/category_explorer.py:74 -#: apps/insights/utils/category_explorer.py:157 +#: apps/insights/utils/category_explorer.py:70 +#: apps/insights/utils/category_explorer.py:149 #: templates/cotton/ui/percentage_distribution.html:24 #: templates/cotton/ui/percentage_distribution.html:28 #: templates/insights/fragments/category_explorer/charts/account.html:66 @@ -883,21 +883,21 @@ msgstr "" msgid "Current Expenses" msgstr "" -#: apps/insights/utils/category_explorer.py:78 -#: apps/insights/utils/category_explorer.py:161 +#: apps/insights/utils/category_explorer.py:74 +#: apps/insights/utils/category_explorer.py:153 #: templates/cotton/ui/percentage_distribution.html:3 #: templates/cotton/ui/percentage_distribution.html:7 -#: templates/insights/fragments/category_explorer/charts/account.html:72 -#: templates/insights/fragments/category_explorer/charts/currency.html:72 +#: templates/insights/fragments/category_explorer/charts/account.html:78 +#: templates/insights/fragments/category_explorer/charts/currency.html:78 msgid "Projected Income" msgstr "" -#: apps/insights/utils/category_explorer.py:82 -#: apps/insights/utils/category_explorer.py:165 +#: apps/insights/utils/category_explorer.py:78 +#: apps/insights/utils/category_explorer.py:157 #: templates/cotton/ui/percentage_distribution.html:17 #: templates/cotton/ui/percentage_distribution.html:21 -#: templates/insights/fragments/category_explorer/charts/account.html:78 -#: templates/insights/fragments/category_explorer/charts/currency.html:78 +#: templates/insights/fragments/category_explorer/charts/account.html:60 +#: templates/insights/fragments/category_explorer/charts/currency.html:60 msgid "Projected Expenses" msgstr "" @@ -2392,8 +2392,8 @@ msgstr "" msgid "Confirm" msgstr "" -#: templates/insights/fragments/category_explorer/charts/account.html:99 -#: templates/insights/fragments/category_explorer/charts/currency.html:91 +#: templates/insights/fragments/category_explorer/charts/account.html:100 +#: templates/insights/fragments/category_explorer/charts/currency.html:92 #: templates/monthly_overview/fragments/monthly_account_summary.html:14 #: templates/monthly_overview/fragments/monthly_currency_summary.html:13 #: templates/transactions/fragments/all_account_summary.html:14 @@ -2413,6 +2413,18 @@ msgstr "" msgid "Income/Expense by Currency" msgstr "" +#: templates/insights/fragments/late_transactions.html:15 +msgid "All good!" +msgstr "" + +#: templates/insights/fragments/late_transactions.html:16 +msgid "No late transactions" +msgstr "" + +#: templates/insights/fragments/latest_transactions.html:14 +msgid "No recent transactions" +msgstr "" + #: templates/insights/fragments/sankey.html:93 msgid "From" msgstr "" @@ -2443,18 +2455,26 @@ msgstr "" msgid "Date Range" msgstr "" -#: templates/insights/pages/index.html:82 +#: templates/insights/pages/index.html:81 msgid "Account Flow" msgstr "" -#: templates/insights/pages/index.html:89 +#: templates/insights/pages/index.html:88 msgid "Currency Flow" msgstr "" -#: templates/insights/pages/index.html:96 +#: templates/insights/pages/index.html:95 msgid "Category Explorer" msgstr "" +#: templates/insights/pages/index.html:102 +msgid "Late Transactions" +msgstr "" + +#: templates/insights/pages/index.html:108 +msgid "Latest Transactions" +msgstr "" + #: templates/installment_plans/fragments/add.html:5 msgid "Add installment plan" msgstr "" diff --git a/app/locale/nl/LC_MESSAGES/django.po b/app/locale/nl/LC_MESSAGES/django.po index 033df4b..374c3e9 100644 --- a/app/locale/nl/LC_MESSAGES/django.po +++ b/app/locale/nl/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-02-19 13:44-0300\n" +"POT-Creation-Date: 2025-02-19 23:05-0300\n" "PO-Revision-Date: 2025-02-12 06:58+0100\n" "Last-Translator: Dimitri Decrock \n" "Language-Team: \n" @@ -795,17 +795,17 @@ msgstr "Herstel" msgid "Please upload either a ZIP file or at least one CSV file" msgstr "" -#: apps/export_app/views.py:169 +#: apps/export_app/views.py:168 msgid "You have to select at least one export" msgstr "" -#: apps/export_app/views.py:187 +#: apps/export_app/views.py:186 #, fuzzy #| msgid "Tag updated successfully" msgid "Data restored successfully" msgstr "Label succesvol bijgewerkt" -#: apps/export_app/views.py:199 +#: apps/export_app/views.py:198 msgid "" "There was an error restoring your data. Check the logs for more details." msgstr "" @@ -891,17 +891,17 @@ msgstr "Run met succes verwijderd" msgid "Uncategorized" msgstr "Categorieën" -#: apps/insights/utils/category_explorer.py:70 -#: apps/insights/utils/category_explorer.py:153 +#: apps/insights/utils/category_explorer.py:66 +#: apps/insights/utils/category_explorer.py:145 #: templates/cotton/ui/percentage_distribution.html:10 #: templates/cotton/ui/percentage_distribution.html:14 -#: templates/insights/fragments/category_explorer/charts/account.html:60 -#: templates/insights/fragments/category_explorer/charts/currency.html:60 +#: templates/insights/fragments/category_explorer/charts/account.html:72 +#: templates/insights/fragments/category_explorer/charts/currency.html:72 msgid "Current Income" msgstr "Huidige inkomsten" -#: apps/insights/utils/category_explorer.py:74 -#: apps/insights/utils/category_explorer.py:157 +#: apps/insights/utils/category_explorer.py:70 +#: apps/insights/utils/category_explorer.py:149 #: templates/cotton/ui/percentage_distribution.html:24 #: templates/cotton/ui/percentage_distribution.html:28 #: templates/insights/fragments/category_explorer/charts/account.html:66 @@ -909,21 +909,21 @@ msgstr "Huidige inkomsten" msgid "Current Expenses" msgstr "Huidige uitgaven" -#: apps/insights/utils/category_explorer.py:78 -#: apps/insights/utils/category_explorer.py:161 +#: apps/insights/utils/category_explorer.py:74 +#: apps/insights/utils/category_explorer.py:153 #: templates/cotton/ui/percentage_distribution.html:3 #: templates/cotton/ui/percentage_distribution.html:7 -#: templates/insights/fragments/category_explorer/charts/account.html:72 -#: templates/insights/fragments/category_explorer/charts/currency.html:72 +#: templates/insights/fragments/category_explorer/charts/account.html:78 +#: templates/insights/fragments/category_explorer/charts/currency.html:78 msgid "Projected Income" msgstr "Verwachte inkomsten" -#: apps/insights/utils/category_explorer.py:82 -#: apps/insights/utils/category_explorer.py:165 +#: apps/insights/utils/category_explorer.py:78 +#: apps/insights/utils/category_explorer.py:157 #: templates/cotton/ui/percentage_distribution.html:17 #: templates/cotton/ui/percentage_distribution.html:21 -#: templates/insights/fragments/category_explorer/charts/account.html:78 -#: templates/insights/fragments/category_explorer/charts/currency.html:78 +#: templates/insights/fragments/category_explorer/charts/account.html:60 +#: templates/insights/fragments/category_explorer/charts/currency.html:60 msgid "Projected Expenses" msgstr "Verwachte uitgaven" @@ -2436,8 +2436,8 @@ msgstr "Annuleer" msgid "Confirm" msgstr "Bevestig" -#: templates/insights/fragments/category_explorer/charts/account.html:99 -#: templates/insights/fragments/category_explorer/charts/currency.html:91 +#: templates/insights/fragments/category_explorer/charts/account.html:100 +#: templates/insights/fragments/category_explorer/charts/currency.html:92 #: templates/monthly_overview/fragments/monthly_account_summary.html:14 #: templates/monthly_overview/fragments/monthly_currency_summary.html:13 #: templates/transactions/fragments/all_account_summary.html:14 @@ -2459,6 +2459,22 @@ msgstr "" msgid "Income/Expense by Currency" msgstr "Eenheid Wisselgeld" +#: templates/insights/fragments/late_transactions.html:15 +msgid "All good!" +msgstr "" + +#: templates/insights/fragments/late_transactions.html:16 +#, fuzzy +#| msgid "Filter transactions" +msgid "No late transactions" +msgstr "Filter verrichtingen" + +#: templates/insights/fragments/latest_transactions.html:14 +#, fuzzy +#| msgid "No recurring transactions" +msgid "No recent transactions" +msgstr "Geen terugkerende verrichtingen" + #: templates/insights/fragments/sankey.html:93 msgid "From" msgstr "" @@ -2495,24 +2511,36 @@ msgstr "" msgid "Date Range" msgstr "Datum en Tijd" -#: templates/insights/pages/index.html:82 +#: templates/insights/pages/index.html:81 #, fuzzy #| msgid "Account" msgid "Account Flow" msgstr "Rekening" -#: templates/insights/pages/index.html:89 +#: templates/insights/pages/index.html:88 #, fuzzy #| msgid "Currency Code" msgid "Currency Flow" msgstr "Munteenheids Code" -#: templates/insights/pages/index.html:96 +#: templates/insights/pages/index.html:95 #, fuzzy #| msgid "Category name" msgid "Category Explorer" msgstr "Naam van categorie" +#: templates/insights/pages/index.html:102 +#, fuzzy +#| msgid "Transactions" +msgid "Late Transactions" +msgstr "Verrichtingen" + +#: templates/insights/pages/index.html:108 +#, fuzzy +#| msgid "Transactions" +msgid "Latest Transactions" +msgstr "Verrichtingen" + #: templates/installment_plans/fragments/add.html:5 msgid "Add installment plan" msgstr "Afbetalingsplan toevoegen" diff --git a/app/locale/pt_BR/LC_MESSAGES/django.po b/app/locale/pt_BR/LC_MESSAGES/django.po index 3e4da87..eaae0ff 100644 --- a/app/locale/pt_BR/LC_MESSAGES/django.po +++ b/app/locale/pt_BR/LC_MESSAGES/django.po @@ -8,8 +8,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-02-19 13:44-0300\n" -"PO-Revision-Date: 2025-02-19 13:50-0300\n" +"POT-Creation-Date: 2025-02-19 23:05-0300\n" +"PO-Revision-Date: 2025-02-19 23:06-0300\n" "Last-Translator: Herculino Trotta\n" "Language-Team: \n" "Language: pt_BR\n" @@ -774,7 +774,7 @@ msgstr "Ação de editar de transação" #: apps/export_app/forms.py:143 apps/rules/models.py:290 msgid "Update or create transaction actions" -msgstr "Ações de atualizar ou criar transação " +msgstr "Ações de atualizar ou criar transação" #: apps/export_app/forms.py:176 templates/cotton/transaction/item.html:158 #: templates/cotton/ui/deleted_transactions_action_bar.html:47 @@ -787,15 +787,15 @@ msgstr "Restaurar" msgid "Please upload either a ZIP file or at least one CSV file" msgstr "Carregue um arquivo ZIP ou pelo menos um arquivo CSV" -#: apps/export_app/views.py:169 +#: apps/export_app/views.py:168 msgid "You have to select at least one export" msgstr "É necessário selecionar pelo menos uma exportação" -#: apps/export_app/views.py:187 +#: apps/export_app/views.py:186 msgid "Data restored successfully" msgstr "Dados restaurados com sucesso" -#: apps/export_app/views.py:199 +#: apps/export_app/views.py:198 msgid "" "There was an error restoring your data. Check the logs for more details." msgstr "" @@ -881,17 +881,17 @@ msgstr "Importação apagada com sucesso" msgid "Uncategorized" msgstr "Sem categoria" -#: apps/insights/utils/category_explorer.py:70 -#: apps/insights/utils/category_explorer.py:153 +#: apps/insights/utils/category_explorer.py:66 +#: apps/insights/utils/category_explorer.py:145 #: templates/cotton/ui/percentage_distribution.html:10 #: templates/cotton/ui/percentage_distribution.html:14 -#: templates/insights/fragments/category_explorer/charts/account.html:60 -#: templates/insights/fragments/category_explorer/charts/currency.html:60 +#: templates/insights/fragments/category_explorer/charts/account.html:72 +#: templates/insights/fragments/category_explorer/charts/currency.html:72 msgid "Current Income" msgstr "Renda Atual" -#: apps/insights/utils/category_explorer.py:74 -#: apps/insights/utils/category_explorer.py:157 +#: apps/insights/utils/category_explorer.py:70 +#: apps/insights/utils/category_explorer.py:149 #: templates/cotton/ui/percentage_distribution.html:24 #: templates/cotton/ui/percentage_distribution.html:28 #: templates/insights/fragments/category_explorer/charts/account.html:66 @@ -899,21 +899,21 @@ msgstr "Renda Atual" msgid "Current Expenses" msgstr "Despesas Atuais" -#: apps/insights/utils/category_explorer.py:78 -#: apps/insights/utils/category_explorer.py:161 +#: apps/insights/utils/category_explorer.py:74 +#: apps/insights/utils/category_explorer.py:153 #: templates/cotton/ui/percentage_distribution.html:3 #: templates/cotton/ui/percentage_distribution.html:7 -#: templates/insights/fragments/category_explorer/charts/account.html:72 -#: templates/insights/fragments/category_explorer/charts/currency.html:72 +#: templates/insights/fragments/category_explorer/charts/account.html:78 +#: templates/insights/fragments/category_explorer/charts/currency.html:78 msgid "Projected Income" msgstr "Renda Prevista" -#: apps/insights/utils/category_explorer.py:82 -#: apps/insights/utils/category_explorer.py:165 +#: apps/insights/utils/category_explorer.py:78 +#: apps/insights/utils/category_explorer.py:157 #: templates/cotton/ui/percentage_distribution.html:17 #: templates/cotton/ui/percentage_distribution.html:21 -#: templates/insights/fragments/category_explorer/charts/account.html:78 -#: templates/insights/fragments/category_explorer/charts/currency.html:78 +#: templates/insights/fragments/category_explorer/charts/account.html:60 +#: templates/insights/fragments/category_explorer/charts/currency.html:60 msgid "Projected Expenses" msgstr "Despesas Previstas" @@ -1082,7 +1082,7 @@ msgstr "" #: apps/rules/models.py:289 msgid "Update or create transaction action" -msgstr " Ação de atualizar ou criar transação" +msgstr "Ação de atualizar ou criar transação" #: apps/rules/views.py:52 msgid "Rule deactivated successfully" @@ -2419,8 +2419,8 @@ msgstr "Cancelar" msgid "Confirm" msgstr "Confirmar" -#: templates/insights/fragments/category_explorer/charts/account.html:99 -#: templates/insights/fragments/category_explorer/charts/currency.html:91 +#: templates/insights/fragments/category_explorer/charts/account.html:100 +#: templates/insights/fragments/category_explorer/charts/currency.html:92 #: templates/monthly_overview/fragments/monthly_account_summary.html:14 #: templates/monthly_overview/fragments/monthly_currency_summary.html:13 #: templates/transactions/fragments/all_account_summary.html:14 @@ -2440,6 +2440,18 @@ msgstr "Gasto/Despesa por Conta" msgid "Income/Expense by Currency" msgstr "Gasto/Despesa por Moeda" +#: templates/insights/fragments/late_transactions.html:15 +msgid "All good!" +msgstr "Tudo certo!" + +#: templates/insights/fragments/late_transactions.html:16 +msgid "No late transactions" +msgstr "Nenhuma transação atrasada" + +#: templates/insights/fragments/latest_transactions.html:14 +msgid "No recent transactions" +msgstr "Nenhuma transação recente" + #: templates/insights/fragments/sankey.html:93 msgid "From" msgstr "De" @@ -2470,18 +2482,26 @@ msgstr "Intervalo de Ano" msgid "Date Range" msgstr "Intervalo de Data" -#: templates/insights/pages/index.html:82 +#: templates/insights/pages/index.html:81 msgid "Account Flow" msgstr "Fluxo de Conta" -#: templates/insights/pages/index.html:89 +#: templates/insights/pages/index.html:88 msgid "Currency Flow" msgstr "Fluxo de Moeda" -#: templates/insights/pages/index.html:96 +#: templates/insights/pages/index.html:95 msgid "Category Explorer" msgstr "Explorador de Categoria" +#: templates/insights/pages/index.html:102 +msgid "Late Transactions" +msgstr "Transações Atrasadas" + +#: templates/insights/pages/index.html:108 +msgid "Latest Transactions" +msgstr "Últimas Transações" + #: templates/installment_plans/fragments/add.html:5 msgid "Add installment plan" msgstr "Adicionar parcelamento" diff --git a/app/templates/cotton/msg/empty.html b/app/templates/cotton/msg/empty.html index 248b75f..b1e6fd9 100644 --- a/app/templates/cotton/msg/empty.html +++ b/app/templates/cotton/msg/empty.html @@ -1,7 +1,7 @@
- +

{{ title }}

{{ subtitle }}

diff --git a/app/templates/insights/fragments/category_explorer/charts/currency.html b/app/templates/insights/fragments/category_explorer/charts/currency.html index c30a9c5..f76719e 100644 --- a/app/templates/insights/fragments/category_explorer/charts/currency.html +++ b/app/templates/insights/fragments/category_explorer/charts/currency.html @@ -80,7 +80,7 @@ backgroundColor: '#4dde8080', // Added transparency stack: 'stack0' }, - + ] }, options: chartOptions diff --git a/app/templates/insights/fragments/late_transactions.html b/app/templates/insights/fragments/late_transactions.html new file mode 100644 index 0000000..de11c03 --- /dev/null +++ b/app/templates/insights/fragments/late_transactions.html @@ -0,0 +1,18 @@ +{% load i18n %} + + +
+ {% if transactions %} + {% for transaction in transactions %} + + {% endfor %} + {# Floating bar #} + + {% else %} + + {% endif %} +
diff --git a/app/templates/insights/fragments/latest_transactions.html b/app/templates/insights/fragments/latest_transactions.html new file mode 100644 index 0000000..239b372 --- /dev/null +++ b/app/templates/insights/fragments/latest_transactions.html @@ -0,0 +1,16 @@ +{% load i18n %} + + +
+ {% if transactions %} + {% for transaction in transactions %} + + {% endfor %} + {# Floating bar #} + + {% else %} + + {% endif %} +
diff --git a/app/templates/insights/pages/index.html b/app/templates/insights/pages/index.html index 3ec8aa3..256c9f9 100644 --- a/app/templates/insights/pages/index.html +++ b/app/templates/insights/pages/index.html @@ -72,7 +72,6 @@
-