Add history chart in categories
This commit is contained in:
parent
9fd41851bc
commit
3f92a6d2ba
3 changed files with 28 additions and 7 deletions
|
@ -24,18 +24,15 @@ table.full-width col.bar {width: auto}
|
||||||
right: 0;
|
right: 0;
|
||||||
border-radius: var(--radius) 0 0 var(--radius);
|
border-radius: var(--radius) 0 0 var(--radius);
|
||||||
}
|
}
|
||||||
.plot td.bar.m div:not(.tot) {
|
.plot td.bar.m div {background: var(--red-1)}
|
||||||
background: var(--red-1);
|
.plot td.bar.p div {background: var(--green-1)}
|
||||||
}
|
|
||||||
.plot td.bar.p div:not(.tot) {
|
|
||||||
background: var(--green-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.plot td.bar div.tot {
|
.plot td.bar div.tot {
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
height: .5rem;
|
height: .5rem;
|
||||||
background: black;
|
|
||||||
}
|
}
|
||||||
|
.plot td.bar.m div.tot {background: var(--red)}
|
||||||
|
.plot td.bar.p div.tot {background: var(--green)}
|
||||||
.plot td.bar div.tot span {
|
.plot td.bar div.tot span {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
<link rel="stylesheet"
|
<link rel="stylesheet"
|
||||||
href="{% static 'main/css/table.css' %}"
|
href="{% static 'main/css/table.css' %}"
|
||||||
type="text/css"/>
|
type="text/css"/>
|
||||||
|
<link rel="stylesheet"
|
||||||
|
href="{% static 'main/css/plot.css' %}"
|
||||||
|
type="text/css"/>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>
|
<h1>
|
||||||
|
@ -23,5 +26,7 @@
|
||||||
{% if form.instance.transactions %}
|
{% if form.instance.transactions %}
|
||||||
<h2>{% translate "Transactions" %}</h2>
|
<h2>{% translate "Transactions" %}</h2>
|
||||||
{% include "main/table/transaction.html" %}
|
{% include "main/table/transaction.html" %}
|
||||||
|
<h2>{% translate "History" %}</h2>
|
||||||
|
{% include "main/plot/history.html" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -228,11 +228,30 @@ class CategoryUpdateView(NummiUpdateView):
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
data = super().get_context_data(**kwargs)
|
data = super().get_context_data(**kwargs)
|
||||||
category = data["form"].instance
|
category = data["form"].instance
|
||||||
|
_history = (
|
||||||
|
category.transaction_set.values(month=models.functions.TruncMonth("date"))
|
||||||
|
.annotate(
|
||||||
|
sum_p=models.Sum("value", filter=models.Q(value__gt=0)),
|
||||||
|
sum_m=models.Sum("value", filter=models.Q(value__lt=0)),
|
||||||
|
sum=models.Sum("value"),
|
||||||
|
)
|
||||||
|
.order_by("-month")
|
||||||
|
)
|
||||||
|
|
||||||
return data | {
|
return data | {
|
||||||
"transactions": category.transaction_set.all()[:8],
|
"transactions": category.transaction_set.all()[:8],
|
||||||
"transactions_url": reverse_lazy(
|
"transactions_url": reverse_lazy(
|
||||||
"category_transactions", args=(category.pk,)
|
"category_transactions", args=(category.pk,)
|
||||||
),
|
),
|
||||||
|
"history": {
|
||||||
|
"data": _history,
|
||||||
|
"max": max(
|
||||||
|
_history.aggregate(
|
||||||
|
max=models.Max("sum_p", default=0),
|
||||||
|
min=-models.Min("sum_m", default=0),
|
||||||
|
).values(),
|
||||||
|
),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue