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 | |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 17 | import webnotes |
| 18 | from webnotes.model.doc import Document |
| 19 | |
| 20 | @webnotes.whitelist() |
| 21 | def get(arg=None): |
| 22 | """get todo list""" |
| 23 | return webnotes.conn.sql("""select name, owner, description, date, |
| 24 | priority, checked, reference_type, reference_name, assigned_by |
| 25 | from `tabToDo Item` where owner=%s |
| 26 | order by field(priority, 'High', 'Medium', 'Low') asc, date asc""", |
| 27 | webnotes.session['user'], as_dict=1) |
| 28 | |
| 29 | @webnotes.whitelist() |
| 30 | def edit(arg=None): |
| 31 | args = webnotes.form_dict |
| 32 | |
| 33 | d = Document('ToDo Item', args.get('name') or None) |
| 34 | d.description = args['description'] |
| 35 | d.date = args['date'] |
| 36 | d.priority = args['priority'] |
| 37 | d.checked = args.get('checked', 0) |
| 38 | d.owner = webnotes.session['user'] |
| 39 | d.save(not args.get('name') and 1 or 0) |
| 40 | |
| 41 | if args.get('name') and d.checked: |
| 42 | notify_assignment(d) |
| 43 | |
| 44 | return d.name |
| 45 | |
| 46 | @webnotes.whitelist() |
| 47 | def delete(arg=None): |
| 48 | name = webnotes.form_dict['name'] |
| 49 | d = Document('ToDo Item', name) |
| 50 | if d and d.name: |
| 51 | notify_assignment(d) |
| 52 | webnotes.conn.sql("delete from `tabToDo Item` where name = %s", name) |
| 53 | |
| 54 | def notify_assignment(d): |
| 55 | doc_type = d.reference_type |
| 56 | doc_name = d.reference_name |
| 57 | assigned_by = d.assigned_by |
| 58 | |
| 59 | if doc_type and doc_name and assigned_by: |
| 60 | from webnotes.widgets.form import assign_to |
| 61 | assign_to.notify_assignment(assigned_by, d.owner, doc_type, doc_name) |
| 62 | |