blob: 7a4866b5aa94544721ca954339f44117d4a83ca4 [file] [log] [blame]
Rushabh Mehtace1d5272013-01-09 16:39:27 +05301# ERPNext: Copyright 2013 Web Notes Technologies Pvt Ltd
2# GNU General Public Licnese. See "license.txt"
3
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"""
44 from webnotes.utils import nowdate
45 todays_events = webnotes.conn.sql("""\
46 SELECT COUNT(*) FROM `tabEvent`
47 WHERE owner = %s
48 AND event_type != 'Cancel'
49 AND %s between date(starts_on) and date(ends_on)""", (
50 webnotes.session.user, nowdate()))
51 return todays_events[0][0]
52
53def get_unread_messages():
54 "returns unread (docstatus-0 messages for a user)"
55 return webnotes.conn.sql("""\
56 SELECT count(*)
57 FROM `tabComment`
58 WHERE comment_doctype IN ('My Company', 'Message')
59 AND comment_docname = %s
60 AND ifnull(docstatus,0)=0
61 """, webnotes.user.name)[0][0]
62
63for_module = {
64 "To Do": get_things_todo,
65 "Calendar": get_todays_events,
66 "Messages": get_unread_messages
67}