@@ -435,25 +435,43 @@ def has_upload_permission(doc, ptype="read", user=None):
435435def get_contact_details (employee : str ) -> dict :
436436 """
437437 Returns basic contact details for the given employee.
438-
439- - employee_name as contact_display
440- - prefered_email as contact_email
441- - cell_number as contact_mobile
442- - designation as contact_designation
443- - department as contact_department
444-
445- :param employee: Employee docname
446438 """
447439 if not employee :
448440 frappe .throw (msg = _ ("Employee is required" ), title = _ ("Missing Parameter" ))
449441
450- doc : Employee = frappe .get_doc ("Employee" , employee )
451- doc .check_permission ()
442+ frappe .has_permission ("Employee" , "read" , employee , throw = True )
443+
444+ contact_data = frappe .db .get_value (
445+ "Employee" ,
446+ employee ,
447+ [
448+ "employee_name" ,
449+ "prefered_email" ,
450+ "company_email" ,
451+ "personal_email" ,
452+ "user_id" ,
453+ "cell_number" ,
454+ "designation" ,
455+ "department" ,
456+ ],
457+ as_dict = True ,
458+ )
459+
460+ if not contact_data :
461+ frappe .throw (msg = _ ("Employee {0} not found" ).format (employee ), title = _ ("Not Found" ))
462+
463+ # Email with priority
464+ employee_email = (
465+ contact_data .get ("prefered_email" )
466+ or contact_data .get ("company_email" )
467+ or contact_data .get ("personal_email" )
468+ or contact_data .get ("user_id" )
469+ )
452470
453471 return {
454- "contact_display" : doc .get ("employee_name" ),
455- "contact_email" : doc . get ( "prefered_email" ) ,
456- "contact_mobile" : doc .get ("cell_number" ),
457- "contact_designation" : doc .get ("designation" ),
458- "contact_department" : doc .get ("department" ),
472+ "contact_display" : contact_data .get ("employee_name" ),
473+ "contact_email" : employee_email ,
474+ "contact_mobile" : contact_data .get ("cell_number" ),
475+ "contact_designation" : contact_data .get ("designation" ),
476+ "contact_department" : contact_data .get ("department" ),
459477 }
0 commit comments