Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 1 | import webnotes |
| 2 | |
| 3 | def get_unread_messages(): |
| 4 | "returns unread (docstatus-0 messages for a user)" |
| 5 | return webnotes.conn.sql("""\ |
| 6 | SELECT name, comment |
| 7 | FROM `tabComment` |
| 8 | WHERE comment_doctype IN ('My Company', 'Message') |
| 9 | AND comment_docname = %s |
| 10 | AND ifnull(docstatus,0)=0 |
| 11 | """, webnotes.user.name, as_list=1) |
| 12 | |
| 13 | def get_open_support_tickets(): |
| 14 | """ |
| 15 | Returns a count of open support tickets |
| 16 | """ |
| 17 | from webnotes.utils import cint |
| 18 | open_support_tickets = webnotes.conn.sql("""\ |
| 19 | SELECT COUNT(*) FROM `tabSupport Ticket` |
| 20 | WHERE status = 'Open'""") |
| 21 | return open_support_tickets and cint(open_support_tickets[0][0]) or 0 |
| 22 | |
| 23 | def get_things_todo(): |
| 24 | """ |
| 25 | Returns a count of incomplete todos |
| 26 | """ |
| 27 | from webnotes.utils import cint |
| 28 | incomplete_todos = webnotes.conn.sql("""\ |
| 29 | SELECT COUNT(*) FROM `tabToDo` |
| 30 | WHERE IFNULL(checked, 0) = 0 |
| 31 | AND owner = %s""", webnotes.session.get('user')) |
| 32 | return incomplete_todos and cint(incomplete_todos[0][0]) or 0 |
| 33 | |
| 34 | def get_todays_events(): |
| 35 | """ |
| 36 | Returns a count of todays events in calendar |
| 37 | """ |
| 38 | from webnotes.utils import nowdate, cint |
| 39 | todays_events = webnotes.conn.sql("""\ |
| 40 | SELECT COUNT(*) FROM `tabEvent` |
| 41 | WHERE owner = %s |
| 42 | AND event_type != 'Cancel' |
| 43 | AND event_date = %s""", ( |
| 44 | webnotes.session.get('user'), nowdate())) |
| 45 | return todays_events and cint(todays_events[0][0]) or 0 |
| 46 | |
| 47 | @webnotes.whitelist() |
| 48 | def get_global_status_messages(arg=None): |
| 49 | return { |
| 50 | 'unread_messages': get_unread_messages(), |
| 51 | 'open_support_tickets': get_open_support_tickets(), |
| 52 | 'things_todo': get_things_todo(), |
| 53 | 'todays_events': get_todays_events(), |
| 54 | } |