Anand Doshi | 486f9df | 2012-07-19 13:40:31 +0530 | [diff] [blame] | 1 | from __future__ import unicode_literals |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 2 | import webnotes |
| 3 | |
| 4 | def 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 | |
| 14 | def get_open_support_tickets(): |
| 15 | """ |
| 16 | Returns a count of open support tickets |
| 17 | """ |
| 18 | from webnotes.utils import cint |
| 19 | open_support_tickets = webnotes.conn.sql("""\ |
| 20 | SELECT COUNT(*) FROM `tabSupport Ticket` |
| 21 | WHERE status = 'Open'""") |
| 22 | return open_support_tickets and cint(open_support_tickets[0][0]) or 0 |
| 23 | |
Rushabh Mehta | 07c94ce | 2012-06-04 12:57:23 +0530 | [diff] [blame] | 24 | def get_open_tasks(): |
| 25 | """ |
| 26 | Returns a count of open tasks |
| 27 | """ |
| 28 | from webnotes.utils import cint |
| 29 | return webnotes.conn.sql("""\ |
| 30 | SELECT COUNT(*) FROM `tabTask` |
| 31 | WHERE status = 'Open'""")[0][0] |
| 32 | |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 33 | def get_things_todo(): |
| 34 | """ |
| 35 | Returns a count of incomplete todos |
| 36 | """ |
| 37 | from webnotes.utils import cint |
| 38 | incomplete_todos = webnotes.conn.sql("""\ |
| 39 | SELECT COUNT(*) FROM `tabToDo` |
| 40 | WHERE IFNULL(checked, 0) = 0 |
| 41 | AND owner = %s""", webnotes.session.get('user')) |
| 42 | return incomplete_todos and cint(incomplete_todos[0][0]) or 0 |
| 43 | |
| 44 | def get_todays_events(): |
| 45 | """ |
| 46 | Returns a count of todays events in calendar |
| 47 | """ |
| 48 | from webnotes.utils import nowdate, cint |
| 49 | todays_events = webnotes.conn.sql("""\ |
| 50 | SELECT COUNT(*) FROM `tabEvent` |
| 51 | WHERE owner = %s |
| 52 | AND event_type != 'Cancel' |
| 53 | AND event_date = %s""", ( |
| 54 | webnotes.session.get('user'), nowdate())) |
| 55 | return todays_events and cint(todays_events[0][0]) or 0 |
| 56 | |
| 57 | @webnotes.whitelist() |
| 58 | def get_global_status_messages(arg=None): |
| 59 | return { |
| 60 | 'unread_messages': get_unread_messages(), |
| 61 | 'open_support_tickets': get_open_support_tickets(), |
| 62 | 'things_todo': get_things_todo(), |
| 63 | 'todays_events': get_todays_events(), |
Rushabh Mehta | 07c94ce | 2012-06-04 12:57:23 +0530 | [diff] [blame] | 64 | 'open_tasks': get_open_tasks() |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 65 | } |