fix(members/excursion): fix seminar day calculation and add verbosity in finance overview

pull/153/head
mariusrklein 8 months ago
parent fd4770d295
commit 92d577f1aa

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-04-11 00:56+0200\n" "POT-Creation-Date: 2025-04-11 18:02+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -1411,6 +1411,18 @@ msgstr ""
"Um den zu erhalten, musst du den LJP-Antrag innerhalb von 3 Wochen nach der " "Um den zu erhalten, musst du den LJP-Antrag innerhalb von 3 Wochen nach der "
"Ausfahrt beim Jugendreferat einreichen und formal genehmigt bekommen." "Ausfahrt beim Jugendreferat einreichen und formal genehmigt bekommen."
#: members/templates/admin/freizeit_finance_overview.html
msgid "Seminar hours"
msgstr "Seminar-Stunden"
#: members/templates/admin/freizeit_finance_overview.html
msgid "Seminar days"
msgstr "Seminar-Tage"
#: members/templates/admin/freizeit_finance_overview.html
msgid "Sum"
msgstr "Summe"
#: members/templates/admin/freizeit_finance_overview.html #: members/templates/admin/freizeit_finance_overview.html
msgid "The LJP contributions are configured to be paid to:" msgid "The LJP contributions are configured to be paid to:"
msgstr "Die LJP-Zuschüsse werden ausgezahlt an:" msgstr "Die LJP-Zuschüsse werden ausgezahlt an:"

@ -8,7 +8,7 @@ import csv
from django.db import models from django.db import models
from django.db.models import TextField, ManyToManyField, ForeignKey, Count,\ from django.db.models import TextField, ManyToManyField, ForeignKey, Count,\
Sum, Case, Q, F, When, Value, IntegerField, Subquery, OuterRef Sum, Case, Q, F, When, Value, IntegerField, Subquery, OuterRef
from django.db.models.functions import TruncDate from django.db.models.functions import Cast
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.utils import timezone from django.utils import timezone
from django.utils.html import format_html from django.utils.html import format_html
@ -1293,20 +1293,37 @@ class Freizeit(CommonModel):
"""calculate seminar days based on intervention hours in every day""" """calculate seminar days based on intervention hours in every day"""
# TODO: add tests for this # TODO: add tests for this
if hasattr(self, 'ljpproposal'): if hasattr(self, 'ljpproposal'):
hours_per_day = ( hours_per_day = self.seminar_time_per_day
self.ljpproposal.intervention_set
.annotate(day=TruncDate('date_start')) # Extract the date (without time)
.values('day') # Group by day
.annotate(total_duration=Sum('duration')) # Sum durations for each day
.order_by('day') # Sort results by date
)
# Calculate the total number of seminar days # Calculate the total number of seminar days
# Each day is counted as 1 if total_duration is >= 5 hours, as 0.5 if total_duration is >= 2.5 # Each day is counted as 1 if total_duration is >= 5 hours, as 0.5 if total_duration is >= 2.5
# otherwise 0 # otherwise 0
return sum([min(math.floor(h['total_duration']/cvt_to_decimal(2.5))/2, 1) for h in hours_per_day]) sum_days = sum([h['sum_days'] for h in hours_per_day])
print(hours_per_day)
print(sum_days)
return sum_days
else: else:
return 0 return 0
@property
def seminar_time_per_day(self):
if hasattr(self, 'ljpproposal'):
return (
self.ljpproposal.intervention_set
.annotate(day=Cast('date_start', output_field=models.DateField())) # Force it to date
.values('day') # Group by day
.annotate(total_duration=Sum('duration'))# Sum durations for each day
.annotate(
sum_days=Case(
When(total_duration__gt=5.0, then=Value(1.0)),
When(total_duration__gt=2.5, then=Value(0.5)),
default=Value(0.0),)
)
.order_by('day') # Sort results by date
)
else:
return []
@property @property
def ljp_duration(self): def ljp_duration(self):
"""calculate the duration in days for the LJP""" """calculate the duration in days for the LJP"""

@ -141,6 +141,26 @@ This results in a total contribution of {{ ljp_contributions }}€.
To receive them, you need to submit the LJP-Proposal within 3 weeks after your excursion and have it approved by the finance office.{% endblocktrans %} To receive them, you need to submit the LJP-Proposal within 3 weeks after your excursion and have it approved by the finance office.{% endblocktrans %}
</p> </p>
<table>
<tr>
<td></td>
<td>{% trans "Seminar hours" %}</td>
<td>{% trans "Seminar days" %}</td>
</tr>
{% for day in memberlist.seminar_time_per_day %}
<tr>
<td>{{ day.day }}</td>
<td>{{ day.total_duration }}</td>
<td>{{ day.sum_days }}</td>
</tr>
{% endfor %}
<tr>
<td><b>{% trans "Sum" %}</b></td>
<td></td>
<td>{{ total_seminar_days }}</td>
</tr>
</table>
<p> <p>
{% blocktrans %}The LJP contributions are configured to be paid to:{% endblocktrans %} {% blocktrans %}The LJP contributions are configured to be paid to:{% endblocktrans %}
<table> <table>

Loading…
Cancel
Save