fix(fallback): use required_helpers of room if shift required_helpers is 0

main
Luca 7 months ago
parent 99285186e5
commit f63f565ca6

@ -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(
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"),
),
)
.filter(fallback_count__lt=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"]

Loading…
Cancel
Save