handle estimated payments in the finance view and template

This commit is contained in:
2022-07-17 14:55:11 +02:00
parent 0d0510a0b0
commit 4e587026e1
2 changed files with 13 additions and 5 deletions

View File

@@ -17,8 +17,11 @@
<h2>aktueller Stand</h2> <h2>aktueller Stand</h2>
<ul> <ul>
{% for topic, amount in balance_dict.items %} {% for topic, amounts in balance_dict.items %}
<li>{{ amount }}€ {{ topic }}</li> <li>
{{ amounts.total }}€ {{ topic }}
{% if amounts.estimated %}(davon {{ amounts.estimated }}€ geschätzt){% endif %}
</li>
{% endfor %} {% endfor %}
</ul> </ul>
<p><b>Summe: {{ overall_sum }}€</b></p> <p><b>Summe: {{ overall_sum }}€</b></p>
@@ -33,7 +36,10 @@
<td>{{ payment.date|date:"d.m." }}</td> <td>{{ payment.date|date:"d.m." }}</td>
<td>{{ payment.amount }}€</td> <td>{{ payment.amount }}€</td>
<td>{{ payment.other_party }}</td> <td>{{ payment.other_party }}</td>
<td>{{ payment.note }}</td> <td>
{% if payment.is_estimated %}(geschätzt){% endif %}
{{ payment.note }}
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View File

@@ -38,13 +38,15 @@ class FinanceView(GaehsnitzTemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
balance_dict = defaultdict(int) balance_dict = defaultdict(lambda: defaultdict(int))
detailed_payments = defaultdict(list) detailed_payments = defaultdict(list)
overall_sum = 0 overall_sum = 0
for payment in Payment.objects.filter(date__year=timezone.now().year).order_by("topic", "date"): for payment in Payment.objects.filter(date__year=timezone.now().year).order_by("topic", "date"):
topic_name = Payment.Topic(payment.topic).label topic_name = Payment.Topic(payment.topic).label
sign = 1 if payment.is_incoming() else -1 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 overall_sum += sign * payment.amount
if payment.is_outgoing() and payment.topic != Payment.Topic.bands: if payment.is_outgoing() and payment.topic != Payment.Topic.bands:
detailed_payments[topic_name].append(payment) detailed_payments[topic_name].append(payment)