|
|
|
|
@ -8,6 +8,7 @@ import csv
|
|
|
|
|
from django.db import models
|
|
|
|
|
from django.db.models import TextField, ManyToManyField, ForeignKey, Count,\
|
|
|
|
|
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 import timezone
|
|
|
|
|
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()])
|
|
|
|
|
else:
|
|
|
|
|
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
|
|
|
|
|
def staff_count(self):
|
|
|
|
|
return self.jugendleiter.count()
|
|
|
|
|
@ -1331,12 +1356,19 @@ class Freizeit(CommonModel):
|
|
|
|
|
return cvt_to_decimal(min(self.maximal_ljp_contributions,
|
|
|
|
|
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
|
|
|
|
|
def total_relative_costs(self):
|
|
|
|
|
if not self.statement:
|
|
|
|
|
return 0
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|