Compare commits

..

No commits in common. "278d252cfd292d44e87a31592d116a23927aaff0" and "fcdfd0e9adac0225cd224c61bab6b707e3530a7b" have entirely different histories.

7 changed files with 26 additions and 23 deletions

View file

@ -18,7 +18,7 @@
</thead> </thead>
<tbody> <tbody>
{% spaceless %} {% spaceless %}
{% for cat in categories %} {% for cat in categories.data %}
<tr> <tr>
<th scope="row" class="l"> <th scope="row" class="l">
{% if cat.category %} {% if cat.category %}
@ -34,27 +34,25 @@
</td> </td>
<td class="value">{{ cat.sum_m|pmrvalue }}</td> <td class="value">{{ cat.sum_m|pmrvalue }}</td>
<td class="bar m"> <td class="bar m">
<div style="width: {% widthratio cat.sum_m max -100 %}%"></div> <div style="width: {% widthratio cat.sum_m categories.max -100 %}%"></div>
{% if cat.sum < 0 %} {% if cat.sum < 0 %}
<div class="tot" style="width:{% widthratio cat.sum max -100 %}%"> <div class="tot"
style="width:{% widthratio cat.sum categories.max -100 %}%">
<span>{{ cat.sum|pmrvalue }}</span> <span>{{ cat.sum|pmrvalue }}</span>
</div> </div>
{% endif %} {% endif %}
</td> </td>
<td class="bar p"> <td class="bar p">
<div style="width: {% widthratio cat.sum_p max 100 %}%"></div> <div style="width: {% widthratio cat.sum_p categories.max 100 %}%"></div>
{% if cat.sum > 0 %} {% if cat.sum > 0 %}
<div class="tot" style="width:{% widthratio cat.sum max 100 %}%"> <div class="tot"
style="width:{% widthratio cat.sum categories.max 100 %}%">
<span>{{ cat.sum|pmrvalue }}</span> <span>{{ cat.sum|pmrvalue }}</span>
</div> </div>
{% endif %} {% endif %}
</td> </td>
<td class="value">{{ cat.sum_p|pmrvalue }}</td> <td class="value">{{ cat.sum_p|pmrvalue }}</td>
</tr> </tr>
{% empty %}
<tr>
<td class="empty" colspan="6">{% translate "No transaction" %}</td>
</tr>
{% endfor %} {% endfor %}
{% endspaceless %} {% endspaceless %}
</tbody> </tbody>

View file

@ -1,14 +1,9 @@
from django import template
from django.db import models from django.db import models
register = template.Library()
def get_categories(transactions):
@register.inclusion_tag("category/category_plot.html")
def category_plot(transactions):
categories = ( categories = (
transactions.filter(category__budget=True) transactions.values("category", "category__name", "category__icon")
.values("category", "category__name", "category__icon")
.annotate( .annotate(
sum=models.Sum("value"), sum=models.Sum("value"),
sum_m=models.Sum("value", filter=models.Q(value__lt=0)), sum_m=models.Sum("value", filter=models.Q(value__lt=0)),
@ -17,7 +12,7 @@ def category_plot(transactions):
.order_by("-sum") .order_by("-sum")
) )
return { return {
"categories": categories, "data": categories,
"max": max( "max": max(
categories.aggregate( categories.aggregate(
max=models.Max("sum_p", default=0), max=models.Max("sum_p", default=0),

View file

@ -1,5 +1,6 @@
{% extends "main/form/base.html" %} {% extends "main/form/base.html" %}
{% load i18n main_extras category %} {% load main_extras %}
{% load i18n %}
{% block title_new %} {% block title_new %}
{% translate "Create statement" %} {% translate "Create statement" %}
{% endblock %} {% endblock %}
@ -18,9 +19,11 @@
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block tables %} {% block tables %}
{% if not form.instance|adding %} {% if categories %}
<h3>{% translate "Categories" %}</h3> <h3>{% translate "Categories" %}</h3>
{% category_plot transactions %} {% include "category/category_plot.html" %}
{% endif %}
{% if not form.instance|adding %}
<h3>{% translate "Transactions" %} ({{ form.instance.sum|pmvalue }} / {{ form.instance.diff|pmvalue }})</h3> <h3>{% translate "Transactions" %} ({{ form.instance.sum|pmvalue }} / {{ form.instance.diff|pmvalue }})</h3>
{% include "transaction/transaction_table.html" %} {% include "transaction/transaction_table.html" %}
{% endif %} {% endif %}

View file

@ -1,4 +1,5 @@
from account.models import Account from account.models import Account
from category.utils import get_categories
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.urls import reverse_lazy from django.urls import reverse_lazy
from main.views import NummiCreateView, NummiDeleteView, NummiListView, NummiUpdateView from main.views import NummiCreateView, NummiDeleteView, NummiListView, NummiUpdateView
@ -41,6 +42,8 @@ class StatementUpdateView(NummiUpdateView):
statement = data["form"].instance statement = data["form"].instance
_transactions = statement.transaction_set.all() _transactions = statement.transaction_set.all()
if _transactions:
data["categories"] = get_categories(_transactions)
return data | { return data | {
"account": statement.account, "account": statement.account,

View file

@ -1,5 +1,6 @@
{% extends "transaction/transaction_list.html" %} {% extends "transaction/transaction_list.html" %}
{% load i18n static category %} {% load i18n %}
{% load static %}
{% block link %} {% block link %}
{{ block.super }} {{ block.super }}
<link rel="stylesheet" <link rel="stylesheet"
@ -10,8 +11,8 @@
{% block table %} {% block table %}
<h3>{% translate "Transactions" %}</h3> <h3>{% translate "Transactions" %}</h3>
{{ block.super }} {{ block.super }}
{% if not category %} {% if categories %}
<h3>{% translate "Categories" %}</h3> <h3>{% translate "Categories" %}</h3>
{% category_plot transactions %} {% include "category/category_plot.html" %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View file

@ -1,5 +1,6 @@
from account.models import Account from account.models import Account
from category.models import Category from category.models import Category
from category.utils import get_categories
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.views.generic.dates import MonthArchiveView from django.views.generic.dates import MonthArchiveView
@ -135,6 +136,8 @@ class TransactionMonthView(UserMixin, MonthArchiveView):
context_data = super().get_context_data(**kwargs) context_data = super().get_context_data(**kwargs)
if "category" in self.kwargs: if "category" in self.kwargs:
return context_data | {"category": self.category} return context_data | {"category": self.category}
context_data["categories"] = get_categories(context_data["transactions"])
if "account" in self.kwargs: if "account" in self.kwargs:
return context_data | {"account": self.account} return context_data | {"account": self.account}
return context_data return context_data