fix(excursion/ljp): added intervention-based calculation of seminar duration.

MK/finance_workflow
mariusrklein 9 months ago
parent 1aba1129c5
commit 64b7788887

@ -117,7 +117,7 @@ def generate_ljp_vbk(excursion):
sheet['D19'] = settings.SEKTION sheet['D19'] = settings.SEKTION
sheet['G19'] = title sheet['G19'] = title
sheet['I19'] = f"von {excursion.date:%d.%m.%y} bis {excursion.end:%d.%m.%y}" sheet['I19'] = f"von {excursion.date:%d.%m.%y} bis {excursion.end:%d.%m.%y}"
sheet['J19'] = excursion.duration sheet['J19'] = excursion.ljp_duration
sheet['L19'] = f"{excursion.ljp_participant_count}" sheet['L19'] = f"{excursion.ljp_participant_count}"
sheet['H19'] = excursion.get_ljp_activity_category() sheet['H19'] = excursion.get_ljp_activity_category()
sheet['M19'] = f"{excursion.postcode}, {excursion.place}" sheet['M19'] = f"{excursion.postcode}, {excursion.place}"

@ -8,6 +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.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
@ -1242,7 +1243,31 @@ class Freizeit(CommonModel):
return sum([i.duration for i in self.ljpproposal.intervention_set.all()]) return sum([i.duration for i in self.ljpproposal.intervention_set.all()])
else: else:
return 0 return 0
@property
def total_seminar_days(self):
"""calculate seminar days based on intervention hours in every day"""
if hasattr(self, 'ljpproposal'):
hours_per_day = (
Intervention.objects
.filter(ljp_proposal_id=self.ljpproposal.id)
.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
# Each day is counted as 1 if total_duration is >= 5 hours, as 0.5 if total_duration is >= 2.5
# otherwise 0
return sum([min(math.floor(h['total_duration']/cvt_to_decimal(2.5))/2, 1) for h in hours_per_day])
else:
return 0
@property
def ljp_duration(self):
"""calculate the duration in days for the LJP"""
return min(self.duration, self.total_seminar_days)
@property @property
def staff_count(self): def staff_count(self):
return self.jugendleiter.count() return self.jugendleiter.count()
@ -1331,12 +1356,19 @@ class Freizeit(CommonModel):
return cvt_to_decimal(min(self.maximal_ljp_contributions, return cvt_to_decimal(min(self.maximal_ljp_contributions,
0.9 * float(self.statement.total_bills_theoretic) + float(self.statement.total_staff))) 0.9 * float(self.statement.total_bills_theoretic) + float(self.statement.total_staff)))
@property
def payable_ljp_contributions(self):
"""from the requested ljp contributions, a tax may be deducted for risk reduction"""
if self.statement.ljp_to:
return self.statement.paid_ljp_contributions
return cvt_to_decimal(self.potential_ljp_contributions * cvt_to_decimal(1 - settings.LJP_TAX))
@property @property
def total_relative_costs(self): def total_relative_costs(self):
if not self.statement: if not self.statement:
return 0 return 0
total_costs = self.statement.total_bills_theoretic total_costs = self.statement.total_bills_theoretic
total_contributions = self.statement.total_subsidies + self.potential_ljp_contributions total_contributions = self.statement.total_subsidies + self.payable_ljp_contributions
return total_costs - total_contributions return total_costs - total_contributions
@property @property

@ -36,7 +36,7 @@
\textbf{Sektion:} & {{ settings.SEKTION }} \\ \textbf{Sektion:} & {{ settings.SEKTION }} \\
\textbf{Titel der Maßnahme:} & {% if not memberlist.ljpproposal %}{{ memberlist.name|esc_all }}{% else %}{{ memberlist.ljpproposal.title }} {% endif %} \\ \textbf{Titel der Maßnahme:} & {% if not memberlist.ljpproposal %}{{ memberlist.name|esc_all }}{% else %}{{ memberlist.ljpproposal.title }} {% endif %} \\
\textbf{Interne Ordnungsnummer:} & {{ memberlist.code|esc_all }} \\ \textbf{Interne Ordnungsnummer:} & {{ memberlist.code|esc_all }} \\
\textbf{Anzahl der durchgeführten Lehrgangstage:} & {{ memberlist.duration }} \\ \textbf{Anzahl der durchgeführten Lehrgangstage:} & {{ memberlist.ljp_duration }} \\
\end{tabular} \end{tabular}
\end{table} \end{table}

Loading…
Cancel
Save