From c9b4cd340801ec28a6e19fbd8b8ae0e485fa4b20 Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Mon, 18 Nov 2024 01:17:37 -0300 Subject: [PATCH] fix: wrong calculations --- app/apps/net_worth/views.py | 6 ++++-- app/apps/transactions/utils/calculations.py | 3 +++ app/apps/yearly_overview/views.py | 10 ++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/apps/net_worth/views.py b/app/apps/net_worth/views.py index fc80b5e..9d53758 100644 --- a/app/apps/net_worth/views.py +++ b/app/apps/net_worth/views.py @@ -15,8 +15,10 @@ from apps.transactions.utils.calculations import ( def net_worth_main(request): - transactions_queryset = Transaction.objects.filter(is_paid=True).order_by( - "account__group", + transactions_queryset = Transaction.objects.filter( + is_paid=True, account__is_archived=False + ).order_by( + "account__group__name", "account__name", ) currency_net_worth = calculate_currency_totals( diff --git a/app/apps/transactions/utils/calculations.py b/app/apps/transactions/utils/calculations.py index f79f8f6..96bab5c 100644 --- a/app/apps/transactions/utils/calculations.py +++ b/app/apps/transactions/utils/calculations.py @@ -155,6 +155,7 @@ def calculate_account_totals(transactions_queryset, ignore_empty=False): "account__is_asset", "account__is_archived", "account__group__name", + "account__group__id", "account__currency__id", "account__currency__code", "account__currency__name", @@ -162,6 +163,7 @@ def calculate_account_totals(transactions_queryset, ignore_empty=False): "account__currency__prefix", "account__currency__suffix", "account__exchange_currency", + "id", ).annotate( expense_current=Coalesce( Sum( @@ -239,6 +241,7 @@ def calculate_account_totals(transactions_queryset, ignore_empty=False): "is_asset": total["account__is_asset"], "is_archived": total["account__is_archived"], "group": total["account__group__name"], + "group_id": total["account__group__id"], }, "currency": { "code": total["account__currency__code"], diff --git a/app/apps/yearly_overview/views.py b/app/apps/yearly_overview/views.py index d2b9524..839c105 100644 --- a/app/apps/yearly_overview/views.py +++ b/app/apps/yearly_overview/views.py @@ -72,8 +72,10 @@ def yearly_overview_by_currency(request, year: int): if currency: filter_params["account__currency_id"] = int(currency) - transactions = Transaction.objects.filter(**filter_params).exclude( - Q(category__mute=True) & ~Q(category=None) + transactions = ( + Transaction.objects.filter(**filter_params) + .exclude(Q(category__mute=True) & ~Q(category=None)) + .order_by("account__group__name", "account__name") ) data = calculate_currency_totals(transactions) @@ -144,8 +146,8 @@ def yearly_overview_by_account(request, year: int): if account: filter_params["account_id"] = int(account) - transactions = Transaction.objects.filter(**filter_params).order_by( - "account__group__name", "account__name", "id" + transactions = Transaction.objects.filter(**filter_params).exclude( + Q(category__mute=True) & ~Q(category=None) ) data = calculate_account_totals(transactions)