blob: 0ae31141fedc393e97ddbbf4d5b466a78765577f [file] [log] [blame]
Rushabh Mehtac7dbe292012-08-07 12:12:55 +05301from __future__ import unicode_literals
Anand Doshi82042f12012-04-06 17:54:17 +05302import webnotes
3
4def get_unread_messages():
5 "returns unread (docstatus-0 messages for a user)"
6 return webnotes.conn.sql("""\
7 SELECT name, comment
8 FROM `tabComment`
9 WHERE comment_doctype IN ('My Company', 'Message')
10 AND comment_docname = %s
11 AND ifnull(docstatus,0)=0
12 """, webnotes.user.name, as_list=1)
13
14def get_open_support_tickets():
Rushabh Mehtac7dbe292012-08-07 12:12:55 +053015 """Returns a count of open support tickets"""
Anand Doshi82042f12012-04-06 17:54:17 +053016 from webnotes.utils import cint
17 open_support_tickets = webnotes.conn.sql("""\
18 SELECT COUNT(*) FROM `tabSupport Ticket`
19 WHERE status = 'Open'""")
20 return open_support_tickets and cint(open_support_tickets[0][0]) or 0
21
Rushabh Mehta07c94ce2012-06-04 12:57:23 +053022def get_open_tasks():
Rushabh Mehtac7dbe292012-08-07 12:12:55 +053023 """Returns a count of open tasks"""
Rushabh Mehta07c94ce2012-06-04 12:57:23 +053024 from webnotes.utils import cint
25 return webnotes.conn.sql("""\
26 SELECT COUNT(*) FROM `tabTask`
27 WHERE status = 'Open'""")[0][0]
28
Anand Doshi82042f12012-04-06 17:54:17 +053029def get_things_todo():
Rushabh Mehtac7dbe292012-08-07 12:12:55 +053030 """Returns a count of incomplete todos"""
Anand Doshi82042f12012-04-06 17:54:17 +053031 from webnotes.utils import cint
32 incomplete_todos = webnotes.conn.sql("""\
33 SELECT COUNT(*) FROM `tabToDo`
34 WHERE IFNULL(checked, 0) = 0
35 AND owner = %s""", webnotes.session.get('user'))
36 return incomplete_todos and cint(incomplete_todos[0][0]) or 0
37
38def get_todays_events():
Rushabh Mehtac7dbe292012-08-07 12:12:55 +053039 """Returns a count of todays events in calendar"""
Anand Doshi82042f12012-04-06 17:54:17 +053040 from webnotes.utils import nowdate, cint
41 todays_events = webnotes.conn.sql("""\
42 SELECT COUNT(*) FROM `tabEvent`
43 WHERE owner = %s
44 AND event_type != 'Cancel'
45 AND event_date = %s""", (
46 webnotes.session.get('user'), nowdate()))
47 return todays_events and cint(todays_events[0][0]) or 0
48
Rushabh Mehtac7dbe292012-08-07 12:12:55 +053049def get_unanswered_questions():
50 return len(filter(lambda d: d[0]==0,
51 webnotes.conn.sql("""select (select count(*) from tabAnswer
52 where tabAnswer.question = tabQuestion.name) as answers from tabQuestion""")))
53
Anand Doshi82042f12012-04-06 17:54:17 +053054@webnotes.whitelist()
55def get_global_status_messages(arg=None):
56 return {
57 'unread_messages': get_unread_messages(),
58 'open_support_tickets': get_open_support_tickets(),
59 'things_todo': get_things_todo(),
60 'todays_events': get_todays_events(),
Rushabh Mehtac7dbe292012-08-07 12:12:55 +053061 'open_tasks': get_open_tasks(),
62 'unanswered_questions': get_unanswered_questions()
Anand Doshi82042f12012-04-06 17:54:17 +053063 }