22 lines
977 B
Python
22 lines
977 B
Python
from django.db import migrations
|
|
|
|
|
|
def assign_legacy_contacts(apps, schema_editor):
|
|
OrganizationalUnit = apps.get_model("staff", "OrganizationalUnit")
|
|
ContactGroup = apps.get_model("customers", "ContactGroup")
|
|
CustomerProfile = apps.get_model("customers", "CustomerProfile")
|
|
sales = OrganizationalUnit.objects.filter(slug="sales").first()
|
|
if sales is None or not CustomerProfile.objects.exists():
|
|
return
|
|
group, _ = ContactGroup.objects.get_or_create(
|
|
unit=sales,
|
|
name="مخاطبان فروش",
|
|
defaults={"description": "گروه پیشفرض مخاطبان موجود پیش از راهاندازی دفترچه سازمانی"},
|
|
)
|
|
group.contacts.add(*CustomerProfile.objects.filter(groups__isnull=True))
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [("tickets", "0005_bootstrap_legacy_staff_unit")]
|
|
operations = [migrations.RunPython(assign_legacy_contacts, migrations.RunPython.noop)]
|