diff --git a/app/apps/accounts/migrations/0016_account_untracked_by.py b/app/apps/accounts/migrations/0016_account_untracked_by.py new file mode 100644 index 0000000..ca3b75a --- /dev/null +++ b/app/apps/accounts/migrations/0016_account_untracked_by.py @@ -0,0 +1,20 @@ +# Generated by Django 5.2.4 on 2025-08-09 05:52 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0015_alter_account_owner_alter_account_shared_with_and_more'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AddField( + model_name='account', + name='untracked_by', + field=models.ManyToManyField(blank=True, related_name='untracked_accounts', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/app/apps/accounts/models.py b/app/apps/accounts/models.py index a387206..55c064c 100644 --- a/app/apps/accounts/models.py +++ b/app/apps/accounts/models.py @@ -1,11 +1,11 @@ from django.conf import settings from django.core.exceptions import ValidationError from django.db import models -from django.db.models import Q from django.utils.translation import gettext_lazy as _ -from apps.transactions.models import Transaction +from apps.common.middleware.thread_local import get_current_user from apps.common.models import SharedObject, SharedObjectManager +from apps.transactions.models import Transaction class AccountGroup(SharedObject): @@ -80,7 +80,8 @@ class Account(SharedObject): def __str__(self): return self.name - def is_untracked_by(self, user): + def is_untracked_by(self): + user = get_current_user() return self.untracked_by.filter(pk=user.pk).exists() def clean(self): diff --git a/app/apps/accounts/views/accounts.py b/app/apps/accounts/views/accounts.py index 422a152..d45c746 100644 --- a/app/apps/accounts/views/accounts.py +++ b/app/apps/accounts/views/accounts.py @@ -157,15 +157,15 @@ def account_delete(request, pk): @only_htmx @login_required -@require_http_methods(["POST"]) +@require_http_methods(["GET"]) def account_toggle_untracked(request, pk): account = get_object_or_404(Account, id=pk) - if account.is_untracked_by(request.user): + if account.is_untracked_by(): account.untracked_by.remove(request.user) - messages.success(request, _("Account is now tracked.")) + messages.success(request, _("Account is now tracked")) else: account.untracked_by.add(request.user) - messages.success(request, _("Account is now untracked.")) + messages.success(request, _("Account is now untracked")) return HttpResponse( status=204, diff --git a/app/apps/monthly_overview/views.py b/app/apps/monthly_overview/views.py index 61587fc..8ed59db 100644 --- a/app/apps/monthly_overview/views.py +++ b/app/apps/monthly_overview/views.py @@ -171,10 +171,14 @@ def monthly_account_summary(request, month: int, year: int): @require_http_methods(["GET"]) def monthly_currency_summary(request, month: int, year: int): # Base queryset with all required filters - base_queryset = Transaction.objects.filter( - reference_date__year=year, - reference_date__month=month, - ).exclude(Q(Q(category__mute=True) & ~Q(category=None)) | Q(mute=True)) + base_queryset = ( + Transaction.objects.filter( + reference_date__year=year, + reference_date__month=month, + ) + .exclude(Q(Q(category__mute=True) & ~Q(category=None)) | Q(mute=True)) + .exclude(account__in=request.user.untracked_accounts.all()) + ) currency_data = calculate_currency_totals(base_queryset.all(), ignore_empty=True) currency_percentages = calculate_percentage_distribution(currency_data) diff --git a/app/apps/transactions/views/transactions.py b/app/apps/transactions/views/transactions.py index 496e4ce..286b835 100644 --- a/app/apps/transactions/views/transactions.py +++ b/app/apps/transactions/views/transactions.py @@ -589,7 +589,10 @@ def transaction_all_currency_summary(request): f = TransactionsFilter(request.GET, queryset=transactions) - currency_data = calculate_currency_totals(f.qs.all(), ignore_empty=True) + currency_data = calculate_currency_totals( + f.qs.exclude(account__in=request.user.untracked_accounts.all()), + ignore_empty=True, + ) currency_percentages = calculate_percentage_distribution(currency_data) context = { diff --git a/app/templates/accounts/fragments/list.html b/app/templates/accounts/fragments/list.html index 8aa009a..f5ef5ed 100644 --- a/app/templates/accounts/fragments/list.html +++ b/app/templates/accounts/fragments/list.html @@ -73,15 +73,13 @@ {% endif %} - {% if account.is_untracked_by user %} - - {% else %} + data-bs-title="{% if account.is_untracked_by %}{% translate "Track" %}{% else %}{% translate "Untrack" %}{% endif %}"> + {% if account.is_untracked_by %} + {% else %} + {% endif %} diff --git a/app/templates/cotton/transaction/item.html b/app/templates/cotton/transaction/item.html index 5bb650e..d182af4 100644 --- a/app/templates/cotton/transaction/item.html +++ b/app/templates/cotton/transaction/item.html @@ -33,7 +33,7 @@ {% endif %} -