fix: used get_employees_with_number, strip_number methods

This commit is contained in:
Subin Tom
2022-03-22 16:22:09 +05:30
committed by Suraj Shetty
parent b52962751c
commit 3f46b2a0ce
2 changed files with 17 additions and 21 deletions

View File

@@ -4,7 +4,7 @@
"allow_import": 1, "allow_import": 1,
"allow_rename": 1, "allow_rename": 1,
"autoname": "naming_series:", "autoname": "naming_series:",
"creation": "2013-03-07 09:04:18", "creation": "2022-02-21 11:54:09.632218",
"doctype": "DocType", "doctype": "DocType",
"document_type": "Setup", "document_type": "Setup",
"editable_grid": 1, "editable_grid": 1,
@@ -813,11 +813,12 @@
"idx": 24, "idx": 24,
"image_field": "image", "image_field": "image",
"links": [], "links": [],
"modified": "2022-07-18 20:03:43.188705", "modified": "2022-08-20 13:44:37.088519",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Employee", "name": "Employee",
"name_case": "Title Case", "name_case": "Title Case",
"naming_rule": "By \"Naming Series\" field",
"owner": "Administrator", "owner": "Administrator",
"permissions": [ "permissions": [
{ {

View File

@@ -35,14 +35,11 @@ class CallLog(Document):
# Add Employee Name # Add Employee Name
if self.is_incoming_call(): if self.is_incoming_call():
# Taking the last 10 digits of the number # Taking the last 10 digits of the number
emp_number_reversed = (self.get("to"))[-1:-11:-1] employee_number = strip_number(self.get('to'))
emp_number = emp_number_reversed[-1::-1] employee = get_employees_with_number(self.get("to"))
employee = frappe.get_all("Employee", filters={
"cell_number": ["like", "%"+emp_number+"%"]
}, fields=["first_name", "middle_name", "last_name", "user_id"])
self.call_received_by = get_employee_name(employee[0]) self.call_received_by = employee[0].get("name")
self.employee_user_id = employee[0].get("user_id") or '' self.employee_user_id = employee[0].get("user_id")
def after_insert(self): def after_insert(self):
self.trigger_call_popup() self.trigger_call_popup()
@@ -77,7 +74,8 @@ class CallLog(Document):
def trigger_call_popup(self): def trigger_call_popup(self):
if self.is_incoming_call(): if self.is_incoming_call():
scheduled_employees = get_scheduled_employees_for_popup(self.medium) scheduled_employees = get_scheduled_employees_for_popup(self.medium)
employee_emails = get_employees_with_number(self.to) employees = get_employees_with_number(self.to)
employee_emails = [employee.get("user_id") for employee in employees]
# check if employees with matched number are scheduled to receive popup # check if employees with matched number are scheduled to receive popup
emails = set(scheduled_employees).intersection(employee_emails) emails = set(scheduled_employees).intersection(employee_emails)
@@ -117,20 +115,17 @@ def get_employees_with_number(number):
if not number: if not number:
return [] return []
employee_emails = frappe.cache().hget("employees_with_number", number) employee_doc_name_and_emails = frappe.cache().hget('employees_with_number', number)
if employee_emails: if employee_doc_name_and_emails: return employee_doc_name_and_emails
return employee_emails
employees = frappe.get_all( employee_doc_name_and_emails = frappe.get_all('Employee', filters={
"Employee", 'cell_number': ['like', '%{}%'.format(number)],
filters={"cell_number": ["like", "%{}%".format(number)], "user_id": ["!=", ""]}, 'user_id': ['!=', '']
fields=["user_id"], }, fields=['name', 'user_id'])
)
employee_emails = [employee.user_id for employee in employees] frappe.cache().hset('employees_with_number', number, employee_doc_name_and_emails)
frappe.cache().hset("employees_with_number", number, employee_emails)
return employee_emails return employee_doc_name_and_emails
def link_existing_conversations(doc, state): def link_existing_conversations(doc, state):