Compare commits
No commits in common. "278d252cfd292d44e87a31592d116a23927aaff0" and "fcdfd0e9adac0225cd224c61bab6b707e3530a7b" have entirely different histories.
278d252cfd
...
fcdfd0e9ad
7 changed files with 26 additions and 23 deletions
|
@ -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>
|
||||
|
|
|
@ -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),
|
|
@ -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 %}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue