fix: Update received_by if "to" is changed

This commit is contained in:
Suraj Shetty
2022-04-13 20:12:08 +05:30
parent cef28df8db
commit ff41b8da4e
2 changed files with 11 additions and 6 deletions

View File

@@ -34,11 +34,7 @@ class CallLog(Document):
# Add Employee Name
if self.is_incoming_call():
# Taking the last 10 digits of the number
employees = get_employees_with_number(self.get("to"))
if employees:
self.call_received_by = employees[0].get("name")
self.employee_user_id = employees[0].get("user_id")
self.update_received_by()
def after_insert(self):
self.trigger_call_popup()
@@ -57,6 +53,9 @@ class CallLog(Document):
if not doc_before_save:
return
if self.is_incoming_call() and self.has_value_changed("to"):
self.update_received_by()
if _is_call_missed(doc_before_save, self):
frappe.publish_realtime("call_{id}_missed".format(id=self.id), self)
self.trigger_call_popup()
@@ -94,6 +93,11 @@ class CallLog(Document):
for email in emails:
frappe.publish_realtime("show_call_popup", self, user=email)
def update_received_by(self):
if employees := get_employees_with_number(self.get("to")):
self.call_received_by = employees[0].get("name")
self.employee_user_id = employees[0].get("user_id")
@frappe.whitelist()
def add_call_summary_and_call_type(call_log, summary, call_type):
@@ -114,7 +118,7 @@ def get_employees_with_number(number):
employee_doc_name_and_emails = frappe.get_all(
"Employee",
filters={"cell_number": ["like", "%{}%".format(number)], "user_id": ["!=", ""]},
filters={"cell_number": ["like", f"%{number}%"], "user_id": ["!=", ""]},
fields=["name", "user_id"],
)