From 5b49836bada5666ef73a5c9aa01ae07086d8411a Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Fri, 3 Jan 2025 14:55:16 +0100 Subject: [PATCH] Fix history plot Fix #31 --- nummi/account/templates/account/account_detail.html | 2 +- nummi/category/templates/category/category_detail.html | 2 +- nummi/history/templatetags/history_extras.py | 10 +++++++--- nummi/transaction/views.py | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/nummi/account/templates/account/account_detail.html b/nummi/account/templates/account/account_detail.html index 5b7fa17..6d7e408 100644 --- a/nummi/account/templates/account/account_detail.html +++ b/nummi/account/templates/account/account_detail.html @@ -22,6 +22,6 @@

{% translate "History" %}

- {% history_plot account.transactions %} + {% history_plot account.transactions account=account %}
{% endblock body %} diff --git a/nummi/category/templates/category/category_detail.html b/nummi/category/templates/category/category_detail.html index 3c13cbb..02b9635 100644 --- a/nummi/category/templates/category/category_detail.html +++ b/nummi/category/templates/category/category_detail.html @@ -20,6 +20,6 @@

{% translate "History" %}

- {% history_plot category.transaction_set.all %} + {% history_plot category.transaction_set category=category %}
{% endblock body %} diff --git a/nummi/history/templatetags/history_extras.py b/nummi/history/templatetags/history_extras.py index 7d278f6..e8f940b 100644 --- a/nummi/history/templatetags/history_extras.py +++ b/nummi/history/templatetags/history_extras.py @@ -10,9 +10,13 @@ register = template.Library() @register.inclusion_tag("history/plot.html") def history_plot(transactions, **kwargs): - return kwargs | { - "history": history(transactions.exclude(category__budget=False)), - } + options = kwargs + if "category" in kwargs or "account" in kwargs: + options["history"] = history(transactions.all()) + else: + options["history"] = history(transactions.exclude(category__budget=False)) + + return options @register.simple_tag diff --git a/nummi/transaction/views.py b/nummi/transaction/views.py index 90e681d..c3f854f 100644 --- a/nummi/transaction/views.py +++ b/nummi/transaction/views.py @@ -136,7 +136,7 @@ class TransactionACMixin: Account.objects.filter(user=self.request.user), pk=self.kwargs["account"], ) - return super().get_queryset().filter(account=self.account) + return super().get_queryset().filter(statement__account=self.account) if "category" in self.kwargs: self.category = get_object_or_404( Category.objects.filter(user=self.request.user),