deactivate shift backup assignments if full
parent
12f8c77b80
commit
450556592b
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.0.4 on 2023-05-19 16:24
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("fallback", "0005_alter_teammember_id"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="fallbackassignment",
|
||||||
|
name="was_full",
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,37 @@
|
|||||||
|
from celery import shared_task
|
||||||
|
from .models import FallbackAssignment
|
||||||
|
from shiftregister.app.models import ShiftRegistration
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import transaction
|
||||||
|
from django.utils import timezone
|
||||||
|
from dynamic_preferences.registries import global_preferences_registry
|
||||||
|
from django.db.models import F, Count, Q, ExpressionWrapper, Case, When
|
||||||
|
from datetime import datetime
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
|
||||||
|
global_preferences = global_preferences_registry.manager()
|
||||||
|
|
||||||
|
|
||||||
|
# cron task to send normal messages(reminders,changes) in batches
|
||||||
|
@shared_task
|
||||||
|
def deactivate_fallbacks():
|
||||||
|
for f in FallbackAssignment.objects.annotate(
|
||||||
|
reg_count=Count(
|
||||||
|
"shift__shiftregistration",
|
||||||
|
distinct=True,
|
||||||
|
filter=Q(
|
||||||
|
shift__shiftregistration__state__in=(
|
||||||
|
ShiftRegistration.RegState.REGISTERED,
|
||||||
|
ShiftRegistration.RegState.CHECKED_IN,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
).filter(
|
||||||
|
was_full=False,
|
||||||
|
shift__start_at__lte=timezone.now()
|
||||||
|
+ global_preferences["helper__min_cancel_time"],
|
||||||
|
shift__required_helpers__lte=F("reg_count"),
|
||||||
|
):
|
||||||
|
f.was_full = True
|
||||||
|
f.save()
|
Loading…
Reference in New Issue