Compare commits
2 commits
278d252cfd
...
eabdaf2516
Author | SHA1 | Date | |
---|---|---|---|
eabdaf2516 | |||
574d1d2875 |
4 changed files with 44 additions and 11 deletions
|
@ -58,5 +58,30 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endspaceless %}
|
{% endspaceless %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
{% if categories %}
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th scope="row" colspan="2" class="l">{% translate "Total" %}</th>
|
||||||
|
<td class="value">{{ total_m|pmrvalue }}</td>
|
||||||
|
<td class="bar m">
|
||||||
|
<div style="width: {% widthratio total_m max -100 %}%"></div>
|
||||||
|
{% if total < 0 %}
|
||||||
|
<div class="tot" style="width:{% widthratio total max -100 %}%">
|
||||||
|
<span>{{ total|pmrvalue }}</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td class="bar p">
|
||||||
|
<div style="width: {% widthratio total_p max 100 %}%"></div>
|
||||||
|
{% if total > 0 %}
|
||||||
|
<div class="tot" style="width:{% widthratio total max 100 %}%">
|
||||||
|
<span>{{ total|pmrvalue }}</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td class="value">{{ total_p|pmrvalue }}</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
{% endif %}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
from django import template
|
from django import template
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models.functions import Greatest
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag("category/category_plot.html")
|
@register.inclusion_tag("category/category_plot.html")
|
||||||
def category_plot(transactions):
|
def category_plot(transactions, **kwargs):
|
||||||
categories = (
|
categories = (
|
||||||
transactions.filter(category__budget=True)
|
transactions.filter(category__budget=True)
|
||||||
.values("category", "category__name", "category__icon")
|
.values("category", "category__name", "category__icon")
|
||||||
|
@ -16,12 +17,15 @@ def category_plot(transactions):
|
||||||
)
|
)
|
||||||
.order_by("-sum")
|
.order_by("-sum")
|
||||||
)
|
)
|
||||||
return {
|
return (
|
||||||
|
kwargs
|
||||||
|
| {
|
||||||
"categories": categories,
|
"categories": categories,
|
||||||
"max": max(
|
|
||||||
categories.aggregate(
|
|
||||||
max=models.Max("sum_p", default=0),
|
|
||||||
min=models.Min("sum_m", default=0),
|
|
||||||
).values(),
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
| categories.aggregate(
|
||||||
|
max=Greatest(models.Sum("sum_m"), models.Sum("sum_p")),
|
||||||
|
total_m=models.Sum("sum_m"),
|
||||||
|
total_p=models.Sum("sum_p"),
|
||||||
|
total=models.Sum("value"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
|
@ -70,3 +70,7 @@ table.full-width col.bar {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.plot tfoot {
|
||||||
|
background: var(--bg-01);
|
||||||
|
}
|
||||||
|
|
|
@ -12,6 +12,6 @@
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
{% if not category %}
|
{% if not category %}
|
||||||
<h3>{% translate "Categories" %}</h3>
|
<h3>{% translate "Categories" %}</h3>
|
||||||
{% category_plot transactions %}
|
{% category_plot transactions month=month %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue