fix queue

This commit is contained in:
javad committed 2026-09-11 18:04:51 +03:30
1 parent 049cc41afc
commit 9a1c99cbd3
14 files changed
+237 -32

No files matched your search

@@ -0,0 +1,32 @@
from django.db import migrations
from django.db.models import F
def scope_legacy_tickets(apps, schema_editor):
Ticket = apps.get_model("tickets", "Ticket")
repaired = []
for ticket in Ticket.objects.filter(
owning_unit__isnull=True,
category__unit__isnull=False,
).select_related("category"):
ticket.owning_unit_id = ticket.category.unit_id
repaired.append(ticket)
if repaired:
Ticket.objects.bulk_update(repaired, ["owning_unit"])
Ticket.objects.filter(
assigned_unit__isnull=True,
owning_unit__isnull=False,
).update(assigned_unit_id=F("owning_unit_id"))
if Ticket.objects.filter(owning_unit__isnull=True).exists():
raise RuntimeError(
"Cannot create unit-scoped queues: some tickets and their categories "
"have no organizational unit."
)
class Migration(migrations.Migration):
dependencies = [("tickets", "0015_seed_customer_category_catalog")]
operations = [migrations.RunPython(scope_legacy_tickets, migrations.RunPython.noop)]