fix contacts role

This commit is contained in:
IluaAir
2025-09-30 18:29:42 +03:00
parent 6388522486
commit edfa955edf

View File

@@ -193,28 +193,24 @@ class CreateTenant(Script):
f"Создан префикс {prefix.prefix} для оператора: {tenant.name}"
)
if data.get("contacts_fio"):
try:
role = data.get("contacts_role", ContactRole.objects.first())
except Exception as e:
self.log_failure(f"Ошибка при получении роли контакта: {e}")
contact = Contact(
name=data["contacts_fio"],
phone=data["contacts_phone"],
email=data["contacts_email"],
role=role,
tenant=tenant,
)
try:
contact.full_clean()
contact.save()
self.log_success(f"Создан контакт: {contact.fio}")
self.log_success(f"Создан контакт: {contact.name}")
except Exception as e:
self.log_failure(f"Ошибка при создании контакта: {e}")
try:
contact.role = data.get(
"contacts_role", ContactRole.objects.first()
)
contact.tenant = tenant
contact.save()
self.log_success(f"Связан контакт с оператором: {tenant.name}")
except Exception as e:
self.log_failure(
f"Ошибка при связывании контакта с оператором: {e}"
)
else:
self.log_info(
f"Тестовый режим: Будет создан оператор: {tenant.name} (slug: {tenant.slug})"
@@ -230,6 +226,14 @@ class CreateTenant(Script):
description=data.get("prefix_description") or "",
)
prefix.full_clean()
contact = Contact(
name=data["contacts_fio"],
phone=data["contacts_phone"],
email=data["contacts_email"],
role=data.get("contacts_role", ContactRole.objects.first()),
tenant=tenant,
)
contact.full_clean()
self.log_success("Все данные валидны")
except ValidationError as e:
self.log_failure(f"Ошибка валидации: {e}")