|
|
|
@ -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"]
|
|
|
|
|