Rushabh Mehta | aaf86ba | 2012-02-28 17:40:13 +0530 | [diff] [blame] | 1 | # ERPNext - web based ERP (http://erpnext.com) |
| 2 | # Copyright (C) 2012 Web Notes Technologies Pvt Ltd |
| 3 | # |
| 4 | # This program is free software: you can redistribute it and/or modify |
| 5 | # it under the terms of the GNU General Public License as published by |
| 6 | # the Free Software Foundation, either version 3 of the License, or |
| 7 | # (at your option) any later version. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | # GNU General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
Anand Doshi | 486f9df | 2012-07-19 13:40:31 +0530 | [diff] [blame] | 17 | from __future__ import unicode_literals |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 18 | import webnotes |
| 19 | from webnotes.model.doc import Document |
| 20 | |
| 21 | @webnotes.whitelist() |
| 22 | def get(arg=None): |
| 23 | """get todo list""" |
| 24 | return webnotes.conn.sql("""select name, owner, description, date, |
| 25 | priority, checked, reference_type, reference_name, assigned_by |
Anand Doshi | 64ddb9f | 2012-06-12 19:24:12 +0530 | [diff] [blame] | 26 | from `tabToDo` where (owner=%s or assigned_by=%s) |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 27 | order by field(priority, 'High', 'Medium', 'Low') asc, date asc""", |
Anand Doshi | 64ddb9f | 2012-06-12 19:24:12 +0530 | [diff] [blame] | 28 | (webnotes.session['user'], webnotes.session['user']), as_dict=1) |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 29 | |
| 30 | @webnotes.whitelist() |
| 31 | def edit(arg=None): |
Rushabh Mehta | 6252c13 | 2012-08-07 12:53:49 +0530 | [diff] [blame] | 32 | import markdown2 |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 33 | args = webnotes.form_dict |
| 34 | |
Anand Doshi | fedfd89 | 2012-03-30 12:29:06 +0530 | [diff] [blame] | 35 | d = Document('ToDo', args.get('name') or None) |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 36 | d.description = args['description'] |
| 37 | d.date = args['date'] |
| 38 | d.priority = args['priority'] |
| 39 | d.checked = args.get('checked', 0) |
Anand Doshi | 64ddb9f | 2012-06-12 19:24:12 +0530 | [diff] [blame] | 40 | if not d.owner: d.owner = webnotes.session['user'] |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 41 | d.save(not args.get('name') and 1 or 0) |
| 42 | |
| 43 | if args.get('name') and d.checked: |
| 44 | notify_assignment(d) |
| 45 | |
| 46 | return d.name |
| 47 | |
| 48 | @webnotes.whitelist() |
| 49 | def delete(arg=None): |
| 50 | name = webnotes.form_dict['name'] |
Anand Doshi | fedfd89 | 2012-03-30 12:29:06 +0530 | [diff] [blame] | 51 | d = Document('ToDo', name) |
Rushabh Mehta | 38cc3d6 | 2012-09-07 09:54:19 +0530 | [diff] [blame] | 52 | if d and d.name and d.owner != webnotes.session['user']: |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 53 | notify_assignment(d) |
Anand Doshi | fedfd89 | 2012-03-30 12:29:06 +0530 | [diff] [blame] | 54 | webnotes.conn.sql("delete from `tabToDo` where name = %s", name) |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 55 | |
| 56 | def notify_assignment(d): |
| 57 | doc_type = d.reference_type |
| 58 | doc_name = d.reference_name |
| 59 | assigned_by = d.assigned_by |
| 60 | |
| 61 | if doc_type and doc_name and assigned_by: |
| 62 | from webnotes.widgets.form import assign_to |
| 63 | assign_to.notify_assignment(assigned_by, d.owner, doc_type, doc_name) |
| 64 | |