2
0
Fork 0

fix(fallback): use required_helpers of room if shift required_helpers is 0
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Luca 2024-05-20 22:41:17 +02:00
parent 99285186e5
commit f63f565ca6
1 changed files with 9 additions and 10 deletions

View File

@ -62,19 +62,18 @@ class TeamMember(models.Model):
self._assign_from_bucket(shit_shifts)
def _assign_from_bucket(self, bucket_selector):
free_bucket = (
Event.objects.filter(bucket_selector)
.annotate(
fallback_count=Count("fallbackassignment"),
)
.filter(fallback_count__lt=F("required_helpers"))
bucket = Event.objects.filter(bucket_selector).annotate(
fallback_count=Count("fallbackassignment"),
real_required_helpers=Case(
When(required_helpers=0, then=F("room__required_helpers")),
default=F("required_helpers"),
),
)
free_bucket = bucket.filter(fallback_count__lt=F("real_required_helpers"))
total_slot_count = Event.objects.filter(bucket_selector).aggregate(
sum=Sum("required_helpers")
)["sum"]
total_slot_count = bucket.aggregate(sum=Sum("real_required_helpers"))["sum"]
free_slot_count = free_bucket.annotate(
needed_helpers=F("required_helpers") - F("fallback_count")
needed_helpers=F("real_required_helpers") - F("fallback_count")
).aggregate(sum=Sum("needed_helpers"))["sum"]
quota = global_preferences["helper__fallback_quota"]