Rushabh Mehta | ad45e31 | 2013-11-20 12:59:58 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
Rushabh Mehta | ce1d527 | 2013-01-09 16:39:27 +0530 | [diff] [blame] | 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | import webnotes |
| 6 | |
Rushabh Mehta | 4736c35 | 2013-06-18 15:46:32 +0530 | [diff] [blame] | 7 | for_doctype = { |
Rushabh Mehta | 846678a | 2013-01-10 12:25:25 +0530 | [diff] [blame] | 8 | "Support Ticket": {"status":"Open"}, |
| 9 | "Customer Issue": {"status":"Open"}, |
| 10 | "Task": {"status":"Open"}, |
| 11 | "Lead": {"status":"Open"}, |
Rushabh Mehta | 176829e | 2013-02-11 14:54:30 +0530 | [diff] [blame] | 12 | "Contact": {"status":"Open"}, |
Rushabh Mehta | 846678a | 2013-01-10 12:25:25 +0530 | [diff] [blame] | 13 | "Opportunity": {"docstatus":0}, |
| 14 | "Quotation": {"docstatus":0}, |
| 15 | "Sales Order": {"docstatus":0}, |
| 16 | "Journal Voucher": {"docstatus":0}, |
| 17 | "Sales Invoice": {"docstatus":0}, |
| 18 | "Purchase Invoice": {"docstatus":0}, |
| 19 | "Leave Application": {"status":"Open"}, |
| 20 | "Expense Claim": {"approval_status":"Draft"}, |
Rushabh Mehta | 2e5db35 | 2013-01-16 11:34:26 +0530 | [diff] [blame] | 21 | "Job Applicant": {"status":"Open"}, |
Rushabh Mehta | 846678a | 2013-01-10 12:25:25 +0530 | [diff] [blame] | 22 | "Purchase Receipt": {"docstatus":0}, |
| 23 | "Delivery Note": {"docstatus":0}, |
| 24 | "Stock Entry": {"docstatus":0}, |
Anand Doshi | 236cc17 | 2013-02-18 13:49:15 +0530 | [diff] [blame] | 25 | "Material Request": {"docstatus":0}, |
Rushabh Mehta | 846678a | 2013-01-10 12:25:25 +0530 | [diff] [blame] | 26 | "Purchase Order": {"docstatus":0}, |
| 27 | "Production Order": {"docstatus":0}, |
| 28 | "BOM": {"docstatus":0}, |
| 29 | "Timesheet": {"docstatus":0}, |
Rushabh Mehta | fee642d | 2013-03-01 18:24:52 +0530 | [diff] [blame] | 30 | "Time Log": {"status":"Draft"}, |
| 31 | "Time Log Batch": {"status":"Draft"}, |
Rushabh Mehta | 4736c35 | 2013-06-18 15:46:32 +0530 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | def get_things_todo(): |
| 35 | """Returns a count of incomplete todos""" |
| 36 | incomplete_todos = webnotes.conn.sql("""\ |
| 37 | SELECT COUNT(*) FROM `tabToDo` |
| 38 | WHERE IFNULL(checked, 0) = 0 |
| 39 | AND (owner = %s or assigned_by=%s)""", (webnotes.session.user, webnotes.session.user)) |
| 40 | return incomplete_todos[0][0] |
| 41 | |
| 42 | def get_todays_events(): |
| 43 | """Returns a count of todays events in calendar""" |
Rushabh Mehta | af15a4a | 2013-07-26 19:03:04 +0530 | [diff] [blame] | 44 | from core.doctype.event.event import get_events |
Rushabh Mehta | 4736c35 | 2013-06-18 15:46:32 +0530 | [diff] [blame] | 45 | from webnotes.utils import nowdate |
Rushabh Mehta | af15a4a | 2013-07-26 19:03:04 +0530 | [diff] [blame] | 46 | today = nowdate() |
| 47 | return len(get_events(today, today)) |
Rushabh Mehta | 4736c35 | 2013-06-18 15:46:32 +0530 | [diff] [blame] | 48 | |
| 49 | def get_unread_messages(): |
| 50 | "returns unread (docstatus-0 messages for a user)" |
| 51 | return webnotes.conn.sql("""\ |
| 52 | SELECT count(*) |
| 53 | FROM `tabComment` |
| 54 | WHERE comment_doctype IN ('My Company', 'Message') |
| 55 | AND comment_docname = %s |
| 56 | AND ifnull(docstatus,0)=0 |
| 57 | """, webnotes.user.name)[0][0] |
| 58 | |
Rushabh Mehta | 04cc515 | 2013-11-18 13:22:07 +0530 | [diff] [blame] | 59 | for_module_doctypes = { |
| 60 | "ToDo": "To Do", |
| 61 | "Event": "Calendar", |
| 62 | "Comment": "Messages" |
| 63 | } |
| 64 | |
Rushabh Mehta | 4736c35 | 2013-06-18 15:46:32 +0530 | [diff] [blame] | 65 | for_module = { |
| 66 | "To Do": get_things_todo, |
| 67 | "Calendar": get_todays_events, |
| 68 | "Messages": get_unread_messages |
| 69 | } |