brotherton-erpnext/erpnext/utilities/page/todo/todo.py

62 lines
2.0 KiB
Python
Raw Normal View History

2012-02-28 12:10:13 +00:00
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2012-02-24 05:56:31 +00:00
import webnotes
from webnotes.model.doc import Document
@webnotes.whitelist()
def get(arg=None):
"""get todo list"""
return webnotes.conn.sql("""select name, owner, description, date,
priority, checked, reference_type, reference_name, assigned_by
2012-06-12 13:54:12 +00:00
from `tabToDo` where (owner=%s or assigned_by=%s)
2012-02-24 05:56:31 +00:00
order by field(priority, 'High', 'Medium', 'Low') asc, date asc""",
2012-06-12 13:54:12 +00:00
(webnotes.session['user'], webnotes.session['user']), as_dict=1)
2012-02-24 05:56:31 +00:00
@webnotes.whitelist()
def edit(arg=None):
args = webnotes.form_dict
2012-03-30 06:59:06 +00:00
d = Document('ToDo', args.get('name') or None)
2012-02-24 05:56:31 +00:00
d.description = args['description']
d.date = args['date']
d.priority = args['priority']
d.checked = args.get('checked', 0)
2012-06-12 13:54:12 +00:00
if not d.owner: d.owner = webnotes.session['user']
2012-02-24 05:56:31 +00:00
d.save(not args.get('name') and 1 or 0)
if args.get('name') and d.checked:
notify_assignment(d)
return d.name
@webnotes.whitelist()
def delete(arg=None):
name = webnotes.form_dict['name']
2012-03-30 06:59:06 +00:00
d = Document('ToDo', name)
2012-02-24 05:56:31 +00:00
if d and d.name:
notify_assignment(d)
2012-03-30 06:59:06 +00:00
webnotes.conn.sql("delete from `tabToDo` where name = %s", name)
2012-02-24 05:56:31 +00:00
def notify_assignment(d):
doc_type = d.reference_type
doc_name = d.reference_name
assigned_by = d.assigned_by
if doc_type and doc_name and assigned_by:
from webnotes.widgets.form import assign_to
assign_to.notify_assignment(assigned_by, d.owner, doc_type, doc_name)