diff --git a/aleksis/apps/alsijil/model_extensions.py b/aleksis/apps/alsijil/model_extensions.py index a3d9c14fafedc02858b025ef221d97b08bfb5b90..e1a2bd0ef2a2c49d0bdf124b21a6f550d303176c 100644 --- a/aleksis/apps/alsijil/model_extensions.py +++ b/aleksis/apps/alsijil/model_extensions.py @@ -2,6 +2,7 @@ from django.db.models import FilteredRelation, Q, QuerySet, Value from django.db.models.aggregates import Count, Sum from django.utils.translation import gettext as _ +from aleksis.apps.chronos.models import LessonEvent from aleksis.apps.kolego.models import AbsenceReason from aleksis.core.models import Group, Person, SchoolTerm @@ -137,13 +138,6 @@ def annotate_person_statistics_for_school_term( datetime_end__date__lte=school_term.date_end, ) if group: - documentations = documentations.filter( - pk__in=Documentation.objects.filter(course__groups=group) - .values_list("pk", flat=True) - .union( - Documentation.objects.filter(course__groups__parent_groups=group).values_list( - "pk", flat=True - ) - ) - ) + lesson_events = LessonEvent.objects.filter(LessonEvent.objects.for_group_q(group)) + documentations = documentations.filter(amends__in=lesson_events) return annotate_person_statistics_from_documentations(persons, documentations) diff --git a/aleksis/apps/alsijil/tasks.py b/aleksis/apps/alsijil/tasks.py index 5c0377d7468a56dd6539c18c8ea80e15b69738b6..71de0d315e6a2d7fbb66b99d5298d21b52502429 100644 --- a/aleksis/apps/alsijil/tasks.py +++ b/aleksis/apps/alsijil/tasks.py @@ -7,6 +7,7 @@ from django.utils.translation import gettext as _ from celery.result import allow_join_result from celery.states import SUCCESS +from aleksis.apps.chronos.models import LessonEvent from aleksis.apps.cursus.models import Course from aleksis.apps.kolego.models.absence import AbsenceReason from aleksis.core.models import Group, PDFFile @@ -118,6 +119,13 @@ def generate_full_register_printout( course__groups__parent_groups=group ).values_list("pk", flat=True) ) + .union( + Documentation.objects.filter( + amends__in=LessonEvent.objects.filter( + LessonEvent.objects.for_group_q(group) + ) + ).values_list("pk", flat=True) + ) ) )