handle estimated payments in the finance view and template
This commit is contained in:
@@ -17,8 +17,11 @@
|
||||
<h2>aktueller Stand</h2>
|
||||
|
||||
<ul>
|
||||
{% for topic, amount in balance_dict.items %}
|
||||
<li>{{ amount }}€ {{ topic }}</li>
|
||||
{% for topic, amounts in balance_dict.items %}
|
||||
<li>
|
||||
{{ amounts.total }}€ {{ topic }}
|
||||
{% if amounts.estimated %}(davon {{ amounts.estimated }}€ geschätzt){% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<p><b>Summe: {{ overall_sum }}€</b></p>
|
||||
@@ -33,7 +36,10 @@
|
||||
<td>{{ payment.date|date:"d.m." }}</td>
|
||||
<td>{{ payment.amount }}€</td>
|
||||
<td>{{ payment.other_party }}</td>
|
||||
<td>{{ payment.note }}</td>
|
||||
<td>
|
||||
{% if payment.is_estimated %}(geschätzt){% endif %}
|
||||
{{ payment.note }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
@@ -38,13 +38,15 @@ class FinanceView(GaehsnitzTemplateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
balance_dict = defaultdict(int)
|
||||
balance_dict = defaultdict(lambda: defaultdict(int))
|
||||
detailed_payments = defaultdict(list)
|
||||
overall_sum = 0
|
||||
for payment in Payment.objects.filter(date__year=timezone.now().year).order_by("topic", "date"):
|
||||
topic_name = Payment.Topic(payment.topic).label
|
||||
sign = 1 if payment.is_incoming() else -1
|
||||
balance_dict[topic_name] += sign * payment.amount
|
||||
balance_dict[topic_name]["total"] += sign * payment.amount
|
||||
if payment.is_estimated:
|
||||
balance_dict[topic_name]["estimated"] += sign * payment.amount
|
||||
overall_sum += sign * payment.amount
|
||||
if payment.is_outgoing() and payment.topic != Payment.Topic.bands:
|
||||
detailed_payments[topic_name].append(payment)
|
||||
|
||||
Reference in New Issue
Block a user