fix sms org name
This commit is contained in:
1 parent
9a1c99cbd3
commit
05480970d0
3 files changed
+106
-1
No files matched your search
@@ -0,0 +1,38 @@
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
OLD_PHRASE = "توسط واحد فروش برای شما ثبت شد"
|
||||
NEW_PHRASE = "توسط واحد {unit_name} برای شما ثبت شد"
|
||||
|
||||
|
||||
def use_actual_unit_name(apps, schema_editor):
|
||||
sms_template = apps.get_model("notifications", "SMSTemplate")
|
||||
templates = sms_template.objects.filter(
|
||||
event_type="STAFF_TICKET_CREATED",
|
||||
body__contains=OLD_PHRASE,
|
||||
)
|
||||
|
||||
for template in templates.iterator():
|
||||
template.body = template.body.replace(OLD_PHRASE, NEW_PHRASE)
|
||||
allowed_tags = list(template.allowed_tags or [])
|
||||
if "unit_name" not in allowed_tags:
|
||||
allowed_tags.append("unit_name")
|
||||
template.allowed_tags = allowed_tags
|
||||
template.save(update_fields=["body", "allowed_tags"])
|
||||
|
||||
|
||||
def restore_legacy_phrase(apps, schema_editor):
|
||||
sms_template = apps.get_model("notifications", "SMSTemplate")
|
||||
templates = sms_template.objects.filter(
|
||||
event_type="STAFF_TICKET_CREATED",
|
||||
body__contains=NEW_PHRASE,
|
||||
)
|
||||
for template in templates.iterator():
|
||||
template.body = template.body.replace(NEW_PHRASE, OLD_PHRASE)
|
||||
template.save(update_fields=["body"])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("notifications", "0009_ensure_global_sms_templates")]
|
||||
|
||||
operations = [migrations.RunPython(use_actual_unit_name, restore_legacy_phrase)]
|
||||
@@ -327,7 +327,7 @@ def test_sms_templates_are_database_managed_and_distinguish_ticket_creator():
|
||||
staff_text=SMSTemplate.objects.get(event_type="STAFF_TICKET_CREATED").body
|
||||
assert customer_text!=staff_text
|
||||
assert "از ثبت درخواست شما متشکریم" in customer_text
|
||||
assert "توسط واحد فروش برای شما ثبت شد" in staff_text
|
||||
assert "توسط واحد {unit_name} برای شما ثبت شد" in staff_text
|
||||
assert "{magic_link}" in customer_text and "{first_name}" in customer_text
|
||||
|
||||
@pytest.mark.django_db(transaction=True)
|
||||
|
||||
@@ -70,6 +70,73 @@ def test_group_dispatch_creates_one_isolated_ticket_and_sms_job_per_contact():
|
||||
assert NotificationJob.objects.filter(ticket__in=tickets, channel="SMS", event_type="STAFF_TICKET_CREATED").count() == 2
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_staff_created_ticket_sms_uses_its_actual_organizational_unit(monkeypatch, settings):
|
||||
from apps.integrations.sms.base import SMSResult
|
||||
from apps.notifications.management.commands import process_notifications
|
||||
|
||||
settings.PUBLIC_BASE_URL = "https://support.example.com"
|
||||
finance = OrganizationalUnit.objects.create(name="حسابداری", slug="sms-finance")
|
||||
staff = make_staff("finance-sms-agent", finance)
|
||||
customer = make_contact("finance-sms-customer", "09120000501")
|
||||
category = TicketCategory.objects.create(unit=finance, title="اسناد مالی", slug="sms-financial-documents")
|
||||
ticket = create_ticket(
|
||||
customer=customer,
|
||||
created_by=staff,
|
||||
unit=finance,
|
||||
category=category,
|
||||
subject="ارسال سند مالی",
|
||||
body="لطفاً سند را بررسی کنید.",
|
||||
)
|
||||
captured = {}
|
||||
|
||||
class Provider:
|
||||
def send_message(self, mobile, message):
|
||||
captured.update(mobile=mobile, message=message)
|
||||
return SMSResult(True, "sent")
|
||||
|
||||
monkeypatch.setattr(process_notifications, "get_sms_provider", lambda: Provider())
|
||||
process_notifications._send_sms(NotificationJob.objects.get(ticket=ticket))
|
||||
|
||||
assert "توسط واحد حسابداری برای شما ثبت شد" in captured["message"]
|
||||
assert "توسط واحد فروش" not in captured["message"]
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_group_dispatch_sms_uses_dispatch_organizational_unit(monkeypatch, settings):
|
||||
from apps.integrations.sms.base import SMSResult
|
||||
from apps.notifications.management.commands import process_notifications
|
||||
|
||||
settings.PUBLIC_BASE_URL = "https://support.example.com"
|
||||
warehouse = OrganizationalUnit.objects.get(name="بارگیری انبار")
|
||||
warehouse.permissions.add(Permission.objects.get(codename="dispatch_group_tickets", content_type__app_label="tickets"))
|
||||
staff = make_staff("warehouse-sms-agent", warehouse)
|
||||
customer = make_contact("warehouse-sms-customer", "09120000502")
|
||||
group = ContactGroup.objects.create(name="رانندگان", unit=warehouse)
|
||||
customer.customer_profile.groups.add(group)
|
||||
category = TicketCategory.objects.create(unit=warehouse, title="هماهنگی بار", slug="sms-loading")
|
||||
_, tickets = dispatch_group_tickets(
|
||||
user=staff,
|
||||
unit=warehouse,
|
||||
contact_group=group,
|
||||
category=category,
|
||||
subject="هماهنگی بارگیری",
|
||||
body="زمان بارگیری را اعلام کنید.",
|
||||
)
|
||||
captured = []
|
||||
|
||||
class Provider:
|
||||
def send_message(self, mobile, message):
|
||||
captured.append(message)
|
||||
return SMSResult(True, "sent")
|
||||
|
||||
monkeypatch.setattr(process_notifications, "get_sms_provider", lambda: Provider())
|
||||
process_notifications._send_sms(NotificationJob.objects.get(ticket=tickets[0]))
|
||||
|
||||
assert "توسط واحد بارگیری انبار برای شما ثبت شد" in captured[0]
|
||||
assert "توسط واحد فروش" not in captured[0]
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_group_dispatch_copies_shared_document_into_each_private_ticket():
|
||||
unit=OrganizationalUnit.objects.create(name="مالی گروهی",slug="bulk-finance")
|
||||
|
||||
Reference in new issue
Block a user