fix some bugs
This commit is contained in:
1 parent
b8b3aba855
commit
963fd839dc
22 files changed
+570
-33
No files matched your search
@@ -23,10 +23,15 @@ def _magic_link(job, reason):
|
||||
token,link = TicketMagicLink.issue_with_record(job.ticket, reason=reason, created_by=job.staff_user or job.ticket.owner or job.ticket.created_by)
|
||||
return link, f"{settings.PUBLIC_BASE_URL}/t/{token}/"
|
||||
|
||||
def _sms_context(job,magic_link):
|
||||
profile=getattr(job.customer,"customer_profile",None)
|
||||
def _sms_context(job,magic_link=""):
|
||||
recipient = job.customer or job.ticket.customer
|
||||
profile=getattr(recipient,"customer_profile",None)
|
||||
unit=job.ticket.owning_unit
|
||||
return {"magic_link":magic_link,"first_name":getattr(profile,"first_name","") or "","last_name":getattr(profile,"last_name","") or "","recipient_name":" ".join(filter(None,[getattr(profile,"first_name","") or "",getattr(profile,"last_name","") or ""])),"unit_name":unit.name if unit else "","company_name":getattr(settings,"COMPANY_NAME","لوله گستر گلپایگان"),"ticket_number":job.ticket.ticket_number,"subject":job.ticket.subject,"province":job.ticket.province or getattr(profile,"province","") or "","city":job.ticket.city or getattr(profile,"city","") or "","expert_name":job.ticket.assigned_expert_name}
|
||||
customer_profile=getattr(job.ticket.customer,"customer_profile",None)
|
||||
first_name=getattr(profile,"first_name","") or ""
|
||||
last_name=getattr(profile,"last_name","") or ""
|
||||
recipient_name=" ".join(filter(None,[first_name,last_name])) or "ثبت نشده"
|
||||
return {"magic_link":magic_link,"first_name":first_name,"last_name":last_name,"recipient_name":recipient_name,"unit_name":unit.name if unit else "","company_name":getattr(settings,"COMPANY_NAME","لوله گستر گلپایگان"),"ticket_number":job.ticket.ticket_number,"subject":job.ticket.subject,"province":job.ticket.province or getattr(customer_profile,"province","") or "","city":job.ticket.city or getattr(customer_profile,"city","") or "","expert_name":job.ticket.assigned_expert_name,"customer_mobile":job.ticket.customer.local_mobile or "ثبت نشده","category_name":job.ticket.category.title}
|
||||
|
||||
def _render_sms(event_type,context,unit=None):
|
||||
from string import Formatter
|
||||
@@ -65,10 +70,7 @@ def _send_sms(job):
|
||||
recipient = job.payload.get("recipient_mobile", "")
|
||||
if not recipient:
|
||||
raise ValueError("Unit supervisor mobile is not configured")
|
||||
subject = " ".join(job.ticket.subject.split())[:80] or "بدون موضوع"
|
||||
category = " ".join(job.ticket.category.title.split())[:50]
|
||||
customer_mobile = job.ticket.customer.local_mobile or "ثبت نشده"
|
||||
message = f"تیکت جدید {job.ticket.ticket_number}\nتلفن: {customer_mobile}\nموضوع: {subject}\nدسته: {category}"
|
||||
message = _render_sms(job.event_type, _sms_context(job), job.ticket.owning_unit)
|
||||
return get_sms_provider().send_message(recipient, message), issued
|
||||
if job.event_type == "CUSTOMER_TICKET_CREATED":
|
||||
issued, url = _magic_link(job, "customer_created_ticket")
|
||||
|
||||
Reference in new issue
Block a user