|
|
@ -62,19 +62,18 @@ class TeamMember(models.Model):
|
|
|
|
self._assign_from_bucket(shit_shifts)
|
|
|
|
self._assign_from_bucket(shit_shifts)
|
|
|
|
|
|
|
|
|
|
|
|
def _assign_from_bucket(self, bucket_selector):
|
|
|
|
def _assign_from_bucket(self, bucket_selector):
|
|
|
|
free_bucket = (
|
|
|
|
bucket = Event.objects.filter(bucket_selector).annotate(
|
|
|
|
Event.objects.filter(bucket_selector)
|
|
|
|
|
|
|
|
.annotate(
|
|
|
|
|
|
|
|
fallback_count=Count("fallbackassignment"),
|
|
|
|
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(
|
|
|
|
total_slot_count = bucket.aggregate(sum=Sum("real_required_helpers"))["sum"]
|
|
|
|
sum=Sum("required_helpers")
|
|
|
|
|
|
|
|
)["sum"]
|
|
|
|
|
|
|
|
free_slot_count = free_bucket.annotate(
|
|
|
|
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"]
|
|
|
|
).aggregate(sum=Sum("needed_helpers"))["sum"]
|
|
|
|
|
|
|
|
|
|
|
|
quota = global_preferences["helper__fallback_quota"]
|
|
|
|
quota = global_preferences["helper__fallback_quota"]
|
|
|
|