Rushabh Mehta | ce1d527 | 2013-01-09 16:39:27 +0530 | [diff] [blame] | 1 | # ERPNext: Copyright 2013 Web Notes Technologies Pvt Ltd |
| 2 | # GNU General Public Licnese. See "license.txt" |
| 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""" |
| 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 | |
| 53 | def 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 | |
| 63 | for_module = { |
| 64 | "To Do": get_things_todo, |
| 65 | "Calendar": get_todays_events, |
| 66 | "Messages": get_unread_messages |
| 67 | } |