From b6365b729e17363a0ade5d8e670888a3f174cd48 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Mon, 15 Jan 2018 14:12:41 +0530 Subject: [PATCH] Deleted Previous Chat Reference for Leave Application Approval (#12482) * deleted previous chat reference * txt to messge * removed comment --- .../leave_application/leave_application.py | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index 1135099733..bfa163a490 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -284,10 +284,42 @@ class LeaveApplication(Document): def notify(self, args): args = frappe._dict(args) - from frappe.desk.page.chat.chat import post - post(**{"txt": args.message, "contact": args.message_to, "subject": args.subject, - "notify": cint(self.follow_via_email)}) + # args -> message, message_to, subject + d = frappe.new_doc('Communication') + d.communication_type = 'Notification' + d.subject = args.subject + d.content = args.message + d.reference_doctype = 'User' + d.reference_name = args.message_to + d.sender = frappe.session.user + + d.insert(ignore_permissions = True) + + if cint(self.follow_via_email): + contact = args.message_to + if not isinstance(contact, list): + contact = [frappe.get_doc('User', contact).email or contact] + + sender = dict() + sender['email'] = frappe.get_doc('User', frappe.session.user).email + sender['full_name'] = frappe.utils.get_fullname(sender['email']) + + try: + frappe.sendmail(recipients = contact, + sender = sender['email'], + subject = args.subject or _("New Message from {sender}").format(sender = sender['full_name']), + template = "new_message", + args = { + "from": sender['full_name'], + "message": args.message, + "link": frappe.utils.get_url() + }, + header = [_('New Message'), 'orange'] + ) + except frappe.OutgoingEmailError: + # Arrey! + pass @frappe.whitelist() def get_approvers(doctype, txt, searchfield, start, page_len, filters):