blob: e561c03adf05748776300bce68642ddec09de7c1 [file] [log] [blame]
Rushabh Mehtaad45e312013-11-20 12:59:58 +05301# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302# License: GNU General Public License v3. See license.txt
Rushabh Mehtace1d5272013-01-09 16:39:27 +05303
4from __future__ import unicode_literals
5import webnotes
6
Rushabh Mehta4736c352013-06-18 15:46:32 +05307for_doctype = {
Rushabh Mehta846678a2013-01-10 12:25:25 +05308 "Support Ticket": {"status":"Open"},
9 "Customer Issue": {"status":"Open"},
10 "Task": {"status":"Open"},
11 "Lead": {"status":"Open"},
Rushabh Mehta176829e2013-02-11 14:54:30 +053012 "Contact": {"status":"Open"},
Rushabh Mehta846678a2013-01-10 12:25:25 +053013 "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 Mehta2e5db352013-01-16 11:34:26 +053021 "Job Applicant": {"status":"Open"},
Rushabh Mehta846678a2013-01-10 12:25:25 +053022 "Purchase Receipt": {"docstatus":0},
23 "Delivery Note": {"docstatus":0},
24 "Stock Entry": {"docstatus":0},
Anand Doshi236cc172013-02-18 13:49:15 +053025 "Material Request": {"docstatus":0},
Rushabh Mehta846678a2013-01-10 12:25:25 +053026 "Purchase Order": {"docstatus":0},
27 "Production Order": {"docstatus":0},
28 "BOM": {"docstatus":0},
29 "Timesheet": {"docstatus":0},
Rushabh Mehtafee642d2013-03-01 18:24:52 +053030 "Time Log": {"status":"Draft"},
31 "Time Log Batch": {"status":"Draft"},
Rushabh Mehta4736c352013-06-18 15:46:32 +053032}
33
34def 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
42def get_todays_events():
43 """Returns a count of todays events in calendar"""
Rushabh Mehta39bb8e22013-12-11 15:32:14 +053044 from webnotes.core.doctype.event.event import get_events
Rushabh Mehta4736c352013-06-18 15:46:32 +053045 from webnotes.utils import nowdate
Rushabh Mehtaaf15a4a2013-07-26 19:03:04 +053046 today = nowdate()
47 return len(get_events(today, today))
Rushabh Mehta4736c352013-06-18 15:46:32 +053048
49def 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 Mehta04cc5152013-11-18 13:22:07 +053059for_module_doctypes = {
60 "ToDo": "To Do",
61 "Event": "Calendar",
62 "Comment": "Messages"
63}
64
Rushabh Mehta4736c352013-06-18 15:46:32 +053065for_module = {
66 "To Do": get_things_todo,
67 "Calendar": get_todays_events,
68 "Messages": get_unread_messages
69}