Compare commits

...

3 commits

5 changed files with 71 additions and 3 deletions

View file

@ -52,7 +52,9 @@
{% regroup history.data by month.year as years_list %}
{% for y, year in years_list reversed %}
<tr>
<th>{{ y }}</th>
<th>
<a href="{% url "transaction_year" y %}">{{ y }}</a>
</th>
{% for m in year %}
{% if forloop.parentloop.last and forloop.first %}
{% empty_calendar_cells_start m.month.month %}

View file

@ -66,8 +66,10 @@ table.full-width col.bar {
}
}
tbody tr {
.history & tbody tr {
background: initial;
}
tbody tr {
&.empty {
height: 0.5rem;
}

View file

@ -0,0 +1,22 @@
{% extends "main/list.html" %}
{% load i18n main_extras static category %}
{% block link %}
{{ block.super }}
{% css "main/css/plot.css" %}
{% endblock %}
{% block name %}{{ year|date:"Y" }}{% endblock %}
{% block h2 %}{{ year|date:"Y" }}{% endblock %}
{% block table %}
{% if history %}
<section>
<h3>
{% translate "History" %}
</h2>
{% include "history/plot.html" %}
</section>
{% endif %}
{% if not category %}
<h3>{% translate "Categories" %}</h3>
{% category_plot transactions month=month %}
{% endif %}
{% endblock %}

View file

@ -4,6 +4,11 @@ from . import views
urlpatterns = [
path("list", views.TransactionListView.as_view(), name="transactions"),
path(
"history/<int:year>",
views.TransactionYearView.as_view(),
name="transaction_year",
),
path(
"history/<int:year>/<int:month>",
views.TransactionMonthView.as_view(),

View file

@ -2,7 +2,8 @@ from account.models import Account
from category.models import Category
from django.shortcuts import get_object_or_404
from django.urls import reverse_lazy
from django.views.generic.dates import MonthArchiveView
from django.views.generic.dates import MonthArchiveView, YearArchiveView
from history.utils import history
from main.views import (
NummiCreateView,
NummiDeleteView,
@ -138,3 +139,39 @@ class TransactionMonthView(UserMixin, MonthArchiveView):
if "account" in self.kwargs:
return context_data | {"account": self.account}
return context_data
class TransactionYearView(UserMixin, YearArchiveView):
model = Transaction
date_field = "date"
context_object_name = "transactions"
make_object_list = True
def get_queryset(self):
if "account" in self.kwargs:
self.account = get_object_or_404(
Account.objects.filter(user=self.request.user),
pk=self.kwargs["account"],
)
return super().get_queryset().filter(account=self.account)
if "category" in self.kwargs:
self.category = get_object_or_404(
Category.objects.filter(user=self.request.user),
pk=self.kwargs["category"],
)
return super().get_queryset().filter(category=self.category)
return super().get_queryset()
def get_context_data(self, **kwargs):
context_data = super().get_context_data(**kwargs)
context_data |= {
"history": history(
context_data["transactions"].exclude(category__budget=False)
),
}
if "category" in self.kwargs:
return context_data | {"category": self.category}
if "account" in self.kwargs:
return context_data | {"account": self.account}
return context_data