2012-09-13 14:10:56 +00:00
|
|
|
# ERPNext - web based ERP (http://erpnext.com)
|
|
|
|
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-09-18 13:22:05 +00:00
|
|
|
from __future__ import unicode_literals
|
2012-04-06 12:24:17 +00:00
|
|
|
import webnotes
|
|
|
|
|
|
|
|
def get_unread_messages():
|
|
|
|
"returns unread (docstatus-0 messages for a user)"
|
|
|
|
return webnotes.conn.sql("""\
|
2012-11-13 05:29:11 +00:00
|
|
|
SELECT count(*)
|
2012-04-06 12:24:17 +00:00
|
|
|
FROM `tabComment`
|
|
|
|
WHERE comment_doctype IN ('My Company', 'Message')
|
|
|
|
AND comment_docname = %s
|
|
|
|
AND ifnull(docstatus,0)=0
|
2012-11-13 05:29:11 +00:00
|
|
|
""", webnotes.user.name)[0][0]
|
2012-04-06 12:24:17 +00:00
|
|
|
|
|
|
|
def get_open_support_tickets():
|
2012-08-07 06:42:55 +00:00
|
|
|
"""Returns a count of open support tickets"""
|
2012-04-06 12:24:17 +00:00
|
|
|
open_support_tickets = webnotes.conn.sql("""\
|
|
|
|
SELECT COUNT(*) FROM `tabSupport Ticket`
|
|
|
|
WHERE status = 'Open'""")
|
2013-01-16 06:04:26 +00:00
|
|
|
return open_support_tickets[0][0]
|
2012-04-06 12:24:17 +00:00
|
|
|
|
2012-06-04 07:27:23 +00:00
|
|
|
def get_open_tasks():
|
2012-08-07 06:42:55 +00:00
|
|
|
"""Returns a count of open tasks"""
|
2012-06-04 07:27:23 +00:00
|
|
|
return webnotes.conn.sql("""\
|
|
|
|
SELECT COUNT(*) FROM `tabTask`
|
|
|
|
WHERE status = 'Open'""")[0][0]
|
|
|
|
|
2012-04-06 12:24:17 +00:00
|
|
|
def get_things_todo():
|
2012-08-07 06:42:55 +00:00
|
|
|
"""Returns a count of incomplete todos"""
|
2012-04-06 12:24:17 +00:00
|
|
|
incomplete_todos = webnotes.conn.sql("""\
|
|
|
|
SELECT COUNT(*) FROM `tabToDo`
|
|
|
|
WHERE IFNULL(checked, 0) = 0
|
2012-12-12 10:43:29 +00:00
|
|
|
AND (owner = %s or assigned_by=%s)""", (webnotes.session.user, webnotes.session.user))
|
2013-01-16 06:04:26 +00:00
|
|
|
return incomplete_todos[0][0]
|
2012-04-06 12:24:17 +00:00
|
|
|
|
|
|
|
def get_todays_events():
|
2012-08-07 06:42:55 +00:00
|
|
|
"""Returns a count of todays events in calendar"""
|
2013-01-16 06:04:26 +00:00
|
|
|
from webnotes.utils import nowdate
|
2012-04-06 12:24:17 +00:00
|
|
|
todays_events = webnotes.conn.sql("""\
|
|
|
|
SELECT COUNT(*) FROM `tabEvent`
|
|
|
|
WHERE owner = %s
|
|
|
|
AND event_type != 'Cancel'
|
|
|
|
AND event_date = %s""", (
|
2013-01-16 06:04:26 +00:00
|
|
|
webnotes.session.user, nowdate()))
|
|
|
|
return todays_events[0][0]
|
|
|
|
|
|
|
|
def get_open_leads():
|
|
|
|
return webnotes.conn.sql("""select count(*) from tabLead
|
|
|
|
where status='Open'""")[0][0]
|
2012-04-06 12:24:17 +00:00
|
|
|
|
2012-08-07 06:42:55 +00:00
|
|
|
def get_unanswered_questions():
|
|
|
|
return len(filter(lambda d: d[0]==0,
|
|
|
|
webnotes.conn.sql("""select (select count(*) from tabAnswer
|
|
|
|
where tabAnswer.question = tabQuestion.name) as answers from tabQuestion""")))
|
|
|
|
|
2012-04-06 12:24:17 +00:00
|
|
|
@webnotes.whitelist()
|
|
|
|
def get_global_status_messages(arg=None):
|
|
|
|
return {
|
|
|
|
'unread_messages': get_unread_messages(),
|
|
|
|
'open_support_tickets': get_open_support_tickets(),
|
|
|
|
'things_todo': get_things_todo(),
|
|
|
|
'todays_events': get_todays_events(),
|
2012-08-07 06:42:55 +00:00
|
|
|
'open_tasks': get_open_tasks(),
|
2013-01-16 06:04:26 +00:00
|
|
|
'unanswered_questions': get_unanswered_questions(),
|
|
|
|
'open_leads': get_open_leads()
|
2012-04-06 12:24:17 +00:00
|
|
|
}
|