blob: 1b54478ecae1cbbf9f49af681a6e5984346ec8a4 [file] [log] [blame]
Rushabh Mehtaaaf86ba2012-02-28 17:40:13 +05301# 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 Mehta2886b952012-02-24 11:26:31 +053017import webnotes
18from webnotes.model.doc import Document
19
20@webnotes.whitelist()
21def 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
Anand Doshi64ddb9f2012-06-12 19:24:12 +053025 from `tabToDo` where (owner=%s or assigned_by=%s)
Rushabh Mehta2886b952012-02-24 11:26:31 +053026 order by field(priority, 'High', 'Medium', 'Low') asc, date asc""",
Anand Doshi64ddb9f2012-06-12 19:24:12 +053027 (webnotes.session['user'], webnotes.session['user']), as_dict=1)
Rushabh Mehta2886b952012-02-24 11:26:31 +053028
29@webnotes.whitelist()
30def edit(arg=None):
31 args = webnotes.form_dict
32
Anand Doshifedfd892012-03-30 12:29:06 +053033 d = Document('ToDo', args.get('name') or None)
Rushabh Mehta2886b952012-02-24 11:26:31 +053034 d.description = args['description']
35 d.date = args['date']
36 d.priority = args['priority']
37 d.checked = args.get('checked', 0)
Anand Doshi64ddb9f2012-06-12 19:24:12 +053038 if not d.owner: d.owner = webnotes.session['user']
Rushabh Mehta2886b952012-02-24 11:26:31 +053039 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()
47def delete(arg=None):
48 name = webnotes.form_dict['name']
Anand Doshifedfd892012-03-30 12:29:06 +053049 d = Document('ToDo', name)
Rushabh Mehta2886b952012-02-24 11:26:31 +053050 if d and d.name:
51 notify_assignment(d)
Anand Doshifedfd892012-03-30 12:29:06 +053052 webnotes.conn.sql("delete from `tabToDo` where name = %s", name)
Rushabh Mehta2886b952012-02-24 11:26:31 +053053
54def 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