From d4a3c9cc0b0f2480a5de1376805292e42269223e Mon Sep 17 00:00:00 2001 From: mariusrklein <47218379+mariusrklein@users.noreply.github.com> Date: Thu, 27 Mar 2025 21:48:27 +0100 Subject: [PATCH] fix(members/freizeit): changed age calculation to first day of excursion --- jdav_web/members/models.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/jdav_web/members/models.py b/jdav_web/members/models.py index 0ef6dc2..d18b06f 100644 --- a/jdav_web/members/models.py +++ b/jdav_web/members/models.py @@ -1,4 +1,4 @@ -from datetime import datetime, timedelta +from datetime import datetime, timedelta, date import uuid import math import pytz @@ -257,6 +257,10 @@ class Person(Contact): age.admin_order_field = 'birth_date' age.short_description = _('age') + def age_at(self, date: date): + """Age of member at a given date""" + return relativedelta(date.replace(tzinfo=None), self.birth_date).years + @property def birth_date_str(self): if self.birth_date is None: @@ -1252,7 +1256,7 @@ class Freizeit(CommonModel): # non-youth leader participants ps_only = ps - jls # participants of the correct age - ps_correct_age = {m for m in ps_only if m.age() >= 6 and m.age() < 27} + ps_correct_age = {m for m in ps_only if m.age_at(self.date) >= 6 and m.age_at(self.date) < 27} # m = the official non-youth-leader participant count # and, assuming there exist enough participants, unrounded m satisfies the equation # len(ps_correct_age) + 1/5 * m = m @@ -1340,9 +1344,9 @@ class Freizeit(CommonModel): jls = set(self.jugendleiter.distinct()) participants = members - jls b27_local = len([m for m in participants - if m.age() <= 27 and settings.SEKTION in m.town]) + if m.age_at(self.date) <= 27 and settings.SEKTION in m.town]) b27_non_local = len([m for m in participants - if m.age() <= 27 and not settings.SEKTION in m.town]) + if m.age_at(self.date) <= 27 and not settings.SEKTION in m.town]) staff = len(jls) total = b27_local + b27_non_local + len(jls) relevant_b27 = min(b27_local + b27_non_local, math.floor(3/2 * b27_local)) @@ -1387,7 +1391,7 @@ class Freizeit(CommonModel): suffix = str(i + 1) base['Vor- und Nachname' + suffix] = m.name base['Anschrift' + suffix] = m.address - base['Alter' + suffix] = str(m.age()) + base['Alter' + suffix] = str(m.age_at(self.date)) base['Status' + str(i+1)] = '2' if m in jls else 'Auswahl1' if settings.SEKTION in m.address else 'Auswahl2' return base -- 2.38.4