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>
<tbody>
{% spaceless %}
{% for cat in categories %}
{% for cat in categories.data %}
<tr>
<th scope="row" class="l">
{% if cat.category %}
@ -34,27 +34,25 @@
</td>
<td class="value">{{ cat.sum_m|pmrvalue }}</td>
<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 %}
<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>
</div>
{% endif %}
</td>
<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 %}
<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>
</div>
{% endif %}
</td>
<td class="value">{{ cat.sum_p|pmrvalue }}</td>
</tr>
{% empty %}
<tr>
<td class="empty" colspan="6">{% translate "No transaction" %}</td>
</tr>
{% endfor %}
{% endspaceless %}
</tbody>

View file

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

View file

@ -1,5 +1,6 @@
{% extends "main/form/base.html" %}
{% load i18n main_extras category %}
{% load main_extras %}
{% load i18n %}
{% block title_new %}
{% translate "Create statement" %}
{% endblock %}
@ -18,9 +19,11 @@
{% endif %}
{% endblock %}
{% block tables %}
{% if not form.instance|adding %}
{% if categories %}
<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>
{% include "transaction/transaction_table.html" %}
{% endif %}

View file

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

View file

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

View file

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