voip click2calll

This commit is contained in:
javad committed 2026-09-26 12:51:12 +03:30
1 parent cb92abbb41
commit 38b1cf06df
18 files changed
+543 -26

No files matched your search

+4 -4
View File
@@ -58,10 +58,10 @@ class StaffProfileInline(admin.StackedInline):
@admin.register(User)
class CustomUserAdmin(UserAdmin):
fieldsets = UserAdmin.fieldsets + (("سامانه تیکت", {"fields": ("mobile", "account_type")}),)
add_fieldsets = UserAdmin.add_fieldsets + (("سامانه تیکت", {"fields": ("mobile", "account_type")}),)
list_display = ("username", "mobile", "account_type", "is_active", "is_staff")
list_filter = UserAdmin.list_filter + ("account_type",)
fieldsets = UserAdmin.fieldsets + (("سامانه تیکت", {"fields": ("mobile", "account_type", "voip_extension", "voip_mobile", "voip_call")}),)
add_fieldsets = UserAdmin.add_fieldsets + (("سامانه تیکت", {"fields": ("mobile", "account_type", "voip_extension", "voip_mobile", "voip_call")}),)
list_display = ("username", "mobile", "voip_extension", "voip_mobile", "voip_call", "account_type", "is_active", "is_staff")
list_filter = UserAdmin.list_filter + ("account_type", "voip_call")
inlines = (StaffProfileInline,)
def save_model(self, request, obj, form, change):
@@ -0,0 +1,23 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [("accounts", "0005_magiclinkaccesslog_magic_opened_idx_and_more")]
operations = [
migrations.AddField(
model_name="user",
name="voip_call",
field=models.BooleanField(default=True, verbose_name="امکان تماس VOIP"),
),
migrations.AddField(
model_name="user",
name="voip_extension",
field=models.CharField(blank=True, max_length=20, verbose_name="شماره داخلی کارشناس"),
),
migrations.AlterField(
model_name="user",
name="mobile",
field=models.CharField(blank=True, max_length=16, null=True, unique=True, verbose_name="شماره موبایل"),
),
]
@@ -0,0 +1,42 @@
from django.db import migrations, models
def copy_staff_mobile_to_voip(apps, schema_editor):
User = apps.get_model("accounts", "User")
User.objects.filter(account_type="STAFF", voip_mobile="", mobile__isnull=False).exclude(mobile="").update(
voip_mobile=models.F("mobile")
)
def clear_copied_voip_mobile(apps, schema_editor):
User = apps.get_model("accounts", "User")
User.objects.filter(account_type="STAFF", voip_mobile=models.F("mobile")).update(voip_mobile="")
class Migration(migrations.Migration):
dependencies = [("accounts", "0006_user_voip_call_user_voip_extension_and_more")]
operations = [
migrations.AddField(
model_name="user",
name="voip_mobile",
field=models.CharField(
blank=True,
help_text="مستقل از شماره حساب مشتری است و می‌تواند تکراری باشد.",
max_length=16,
verbose_name="شماره موبایل کارشناس برای VOIP",
),
),
migrations.AlterField(
model_name="user",
name="mobile",
field=models.CharField(
blank=True,
max_length=16,
null=True,
unique=True,
verbose_name="شماره موبایل حساب",
),
),
migrations.RunPython(copy_staff_mobile_to_voip, clear_copied_voip_mobile),
]
+13 -1
View File
@@ -19,14 +19,26 @@ class User(PublicIdModel, AbstractUser):
class AccountType(models.TextChoices):
CUSTOMER = "CUSTOMER", "مشتری"
STAFF = "STAFF", "کارشناس"
mobile = models.CharField(max_length=16, unique=True, null=True, blank=True)
mobile = models.CharField("شماره موبایل حساب", max_length=16, unique=True, null=True, blank=True)
account_type = models.CharField(max_length=10, choices=AccountType.choices, default=AccountType.CUSTOMER)
voip_extension = models.CharField("شماره داخلی کارشناس", max_length=20, blank=True)
voip_mobile = models.CharField(
"شماره موبایل کارشناس برای VOIP",
max_length=16,
blank=True,
help_text="مستقل از شماره حساب مشتری است و می‌تواند تکراری باشد.",
)
voip_call = models.BooleanField("امکان تماس VOIP", default=True)
def save(self, *args, **kwargs):
if self.mobile: self.mobile = normalize_mobile(self.mobile)
if self.voip_mobile: self.voip_mobile = normalize_mobile(self.voip_mobile)
super().save(*args, **kwargs)
@property
def local_mobile(self):
return f"0{self.mobile[3:]}" if self.mobile and self.mobile.startswith("+98") else (self.mobile or "")
@property
def voip_local_mobile(self):
return f"0{self.voip_mobile[3:]}" if self.voip_mobile.startswith("+98") else self.voip_mobile
class OTPChallenge(models.Model):
class Purpose(models.TextChoices): LOGIN = "LOGIN", "ورود"