From bdd45d538abae692bfa307d3f61ef38267c69a55 Mon Sep 17 00:00:00 2001 From: mbauskar Date: Sun, 12 Mar 2017 22:46:46 +0530 Subject: [PATCH] [minor] add unread email count in notification toolbar --- frappe/core/notifications.py | 16 ++++++++++++++++ .../public/js/frappe/ui/toolbar/notifications.js | 1 + 2 files changed, 17 insertions(+) diff --git a/frappe/core/notifications.py b/frappe/core/notifications.py index b689905daa..e48e52f48c 100644 --- a/frappe/core/notifications.py +++ b/frappe/core/notifications.py @@ -16,6 +16,7 @@ def get_notification_config(): "for_other": { "Likes": "frappe.core.notifications.get_unseen_likes", "Chat": "frappe.core.notifications.get_unread_messages", + "Email": "frappe.core.notifications.get_unread_emails", } } @@ -63,3 +64,18 @@ def get_unseen_likes(): and owner is not null and owner!=%(user)s and reference_owner=%(user)s and seen=0""", {"user": frappe.session.user})[0][0] + +def get_unread_emails(): + "returns unread emails for a user" + + return frappe.db.sql("""\ + SELECT count(*) + FROM `tabCommunication` + WHERE communication_type='Communication' + AND communication_medium="Email" + AND email_account in ( + SELECT distinct email_account from `tabUser Email` WHERE parent=%(user)s + ) + AND modified >= DATE_SUB(NOW(),INTERVAL 1 YEAR) + AND seen=0 + """, {"user": frappe.session.user})[0][0] diff --git a/frappe/public/js/frappe/ui/toolbar/notifications.js b/frappe/public/js/frappe/ui/toolbar/notifications.js index ec2ecd2300..5b5abc9b79 100644 --- a/frappe/public/js/frappe/ui/toolbar/notifications.js +++ b/frappe/public/js/frappe/ui/toolbar/notifications.js @@ -83,6 +83,7 @@ frappe.ui.notifications.config = { "ToDo": { label: __("To Do") }, "Chat": { label: __("Chat"), route: "chat"}, "Event": { label: __("Calendar"), route: "List/Event/Calendar" }, + "Email": { label: __("Email"), route: "List/Communication/Inbox" }, "Likes": { label: __("Likes"), click: function() {