Task Notification donw, reminder left
This commit is contained in:
parent
8acb043a8a
commit
b3058a3d5a
@ -18,99 +18,99 @@ convert_to_lists = webnotes.conn.convert_to_lists
|
||||
|
||||
|
||||
class DocType:
|
||||
def __init__(self,d,dl):
|
||||
self.doc, self.doclist = d,dl
|
||||
|
||||
def get_projects(self, arg):
|
||||
# project list
|
||||
pl=[]
|
||||
status={}
|
||||
if arg == 'Open':
|
||||
pl = [p[0] for p in sql("select name from `tabProject` where status = 'Open' order by creation desc limit 20")]
|
||||
for p1 in pl:
|
||||
status[p1] = 'Open'
|
||||
elif arg == 'Completed':
|
||||
pl = [p[0] for p in sql("select name from `tabProject` where status = 'Completed' order by creation desc limit 20")]
|
||||
for p2 in pl:
|
||||
status[p2] = 'Completed'
|
||||
elif arg == 'Cancelled':
|
||||
pl = [p[0] for p in sql("select name from `tabProject` where status = 'Cancelled' order by creation desc limit 20")]
|
||||
for p3 in pl:
|
||||
status[p3] = 'Cancelled'
|
||||
else:
|
||||
#pl = [p[0] for p in sql("select name from `tabProject` order by creation desc limit 20")]
|
||||
pl1 = sql("select name, status from `tabProject` order by creation desc limit 20", as_dict=1)
|
||||
for p4 in pl1:
|
||||
status[p4['name']] = p4['status']
|
||||
pl.append(p4['name'])
|
||||
|
||||
# milestones in the next 7 days for active projects
|
||||
ml = convert_to_lists(sql("select t1.milestone_date, t1.milestone, t1.parent from `tabProject Milestone` t1, tabProject t2 where t1.parent = t2.name and t2.status='Open' and DATEDIFF(t1.milestone_date, CURDATE()) BETWEEN 0 AND 7 ORDER BY t1.milestone_date ASC"))
|
||||
def __init__(self,d,dl):
|
||||
self.doc, self.doclist = d,dl
|
||||
|
||||
def get_projects(self, arg):
|
||||
# project list
|
||||
pl=[]
|
||||
status={}
|
||||
if arg == 'Open':
|
||||
pl = [p[0] for p in sql("select name from `tabProject` where status = 'Open' order by creation desc limit 20")]
|
||||
for p1 in pl:
|
||||
status[p1] = 'Open'
|
||||
elif arg == 'Completed':
|
||||
pl = [p[0] for p in sql("select name from `tabProject` where status = 'Completed' order by creation desc limit 20")]
|
||||
for p2 in pl:
|
||||
status[p2] = 'Completed'
|
||||
elif arg == 'Cancelled':
|
||||
pl = [p[0] for p in sql("select name from `tabProject` where status = 'Cancelled' order by creation desc limit 20")]
|
||||
for p3 in pl:
|
||||
status[p3] = 'Cancelled'
|
||||
else:
|
||||
#pl = [p[0] for p in sql("select name from `tabProject` order by creation desc limit 20")]
|
||||
pl1 = sql("select name, status from `tabProject` order by creation desc limit 20", as_dict=1)
|
||||
for p4 in pl1:
|
||||
status[p4['name']] = p4['status']
|
||||
pl.append(p4['name'])
|
||||
|
||||
# milestones in the next 7 days for active projects
|
||||
ml = convert_to_lists(sql("select t1.milestone_date, t1.milestone, t1.parent from `tabProject Milestone` t1, tabProject t2 where t1.parent = t2.name and t2.status='Open' and DATEDIFF(t1.milestone_date, CURDATE()) BETWEEN 0 AND 7 ORDER BY t1.milestone_date ASC"))
|
||||
|
||||
# percent of activity completed per project
|
||||
comp = {}
|
||||
n_tasks = {}
|
||||
|
||||
for p in pl:
|
||||
t1 = sql('select count(*) from tabTicket where project=%s and docstatus!=2', p)[0][0]
|
||||
n_tasks[p] = t1 or 0
|
||||
if t1:
|
||||
t2 = sql('select count(*) from tabTicket where project=%s and docstatus!=2 and status="Closed"', p)[0][0]
|
||||
comp[p] = cint(flt(t2)*100/t1)
|
||||
|
||||
return {'pl':pl, 'ml':ml, 'comp':comp, 'n_tasks':n_tasks, 'status':status}
|
||||
|
||||
def get_resources(self):
|
||||
ret = {}
|
||||
# percent of activity completed per project
|
||||
comp = {}
|
||||
n_tasks = {}
|
||||
|
||||
for p in pl:
|
||||
t1 = sql('select count(*) from tabTicket where project=%s and docstatus!=2', p)[0][0]
|
||||
n_tasks[p] = t1 or 0
|
||||
if t1:
|
||||
t2 = sql('select count(*) from tabTicket where project=%s and docstatus!=2 and status="Closed"', p)[0][0]
|
||||
comp[p] = cint(flt(t2)*100/t1)
|
||||
|
||||
return {'pl':pl, 'ml':ml, 'comp':comp, 'n_tasks':n_tasks, 'status':status}
|
||||
|
||||
def get_resources(self):
|
||||
ret = {}
|
||||
|
||||
# resource list
|
||||
rl = sql("select distinct allocated_to, assignee_email from tabTicket")
|
||||
# resource list
|
||||
rl = sql("select distinct allocated_to, assignee_email from tabTicket")
|
||||
|
||||
# get open & closed tickets
|
||||
for r in rl:
|
||||
if r[0]:
|
||||
ret[r[1]] = {}
|
||||
ret[r[1]]['id'] = r[0]
|
||||
ret[r[1]]['Total'] = sql("select count(*) from tabTicket where allocated_to=%s and docstatus!=2", r[0])[0][0]
|
||||
ret[r[1]]['Closed'] = sql("select count(*) from tabTicket where allocated_to=%s and status='Closed' and docstatus!=2", r[0])[0][0]
|
||||
ret[r[1]]['percent'] = cint(flt(ret[r[1]]['Closed']) * 100 / ret[r[1]]['Total'])
|
||||
# get open & closed tickets
|
||||
for r in rl:
|
||||
if r[0]:
|
||||
ret[r[1]] = {}
|
||||
ret[r[1]]['id'] = r[0]
|
||||
ret[r[1]]['Total'] = sql("select count(*) from tabTicket where allocated_to=%s and docstatus!=2", r[0])[0][0]
|
||||
ret[r[1]]['Closed'] = sql("select count(*) from tabTicket where allocated_to=%s and status='Closed' and docstatus!=2", r[0])[0][0]
|
||||
ret[r[1]]['percent'] = cint(flt(ret[r[1]]['Closed']) * 100 / ret[r[1]]['Total'])
|
||||
|
||||
return ret
|
||||
return ret
|
||||
|
||||
# --------------------------------------------------------------
|
||||
# for Gantt Chart
|
||||
# --------------------------------------------------------------
|
||||
# for Gantt Chart
|
||||
|
||||
def get_init_data(self, arg=''):
|
||||
pl = [p[0] for p in sql('select name from tabProject where docstatus != 2')]
|
||||
rl = [p[0] for p in sql('select distinct allocated_to from tabTicket where docstatus != 2 and ifnull(allocated_to,"") != ""')]
|
||||
return {'pl':pl, 'rl':rl}
|
||||
def get_init_data(self, arg=''):
|
||||
pl = [p[0] for p in sql('select name from tabProject where docstatus != 2')]
|
||||
rl = [p[0] for p in sql('select distinct allocated_to from tabTicket where docstatus != 2 and ifnull(allocated_to,"") != ""')]
|
||||
return {'pl':pl, 'rl':rl}
|
||||
|
||||
def get_tasks(self, arg):
|
||||
start_date, end_date, project, resource = arg.split('~~~')
|
||||
def get_tasks(self, arg):
|
||||
start_date, end_date, project, resource = arg.split('~~~')
|
||||
|
||||
cl = ''
|
||||
if project and project != 'All':
|
||||
cl = " and ifnull(project,'') = '%s'" % project
|
||||
cl = ''
|
||||
if project and project != 'All':
|
||||
cl = " and ifnull(project,'') = '%s'" % project
|
||||
|
||||
if resource and resource != 'All':
|
||||
cl = " and ifnull(allocated_to,'') = '%s'" % resource
|
||||
if resource and resource != 'All':
|
||||
cl = " and ifnull(allocated_to,'') = '%s'" % resource
|
||||
|
||||
tl = sql("""
|
||||
select subject, allocated_to, project, exp_start_date, exp_end_date, priority, status, name
|
||||
from tabTicket
|
||||
where
|
||||
((exp_start_date between '%(st)s' and '%(end)s') or
|
||||
(exp_end_date between '%(st)s' and '%(end)s') or
|
||||
(exp_start_date < '%(st)s' and exp_end_date > '%(end)s')) %(cond)s order by exp_start_date limit 100""" % {'st': start_date, 'end': end_date, 'cond':cl})
|
||||
tl = sql("""
|
||||
select subject, allocated_to, project, exp_start_date, exp_end_date, priority, status, name
|
||||
from tabTicket
|
||||
where
|
||||
((exp_start_date between '%(st)s' and '%(end)s') or
|
||||
(exp_end_date between '%(st)s' and '%(end)s') or
|
||||
(exp_start_date < '%(st)s' and exp_end_date > '%(end)s')) %(cond)s order by exp_start_date limit 100""" % {'st': start_date, 'end': end_date, 'cond':cl})
|
||||
|
||||
return convert_to_lists(tl)
|
||||
|
||||
def declare_proj_completed(self, arg):
|
||||
chk = sql("select name from `tabTicket` where project=%s and status='Open'", arg)
|
||||
if chk:
|
||||
chk_lst = [x[0] for x in chk]
|
||||
msgprint("Task(s) "+','.join(chk_lst)+" has staus 'Open'. Please submit all tasks against this project before closing the project.")
|
||||
return cstr('false')
|
||||
else:
|
||||
sql("update `tabProject` set status = 'Completed' where name = %s", arg)
|
||||
return cstr('true')
|
||||
return convert_to_lists(tl)
|
||||
|
||||
def declare_proj_completed(self, arg):
|
||||
chk = sql("select name from `tabTicket` where project=%s and status='Open'", arg)
|
||||
if chk:
|
||||
chk_lst = [x[0] for x in chk]
|
||||
msgprint("Task(s) "+','.join(chk_lst)+" has staus 'Open'. Please submit all tasks against this project before closing the project.")
|
||||
return cstr('false')
|
||||
else:
|
||||
sql("update `tabProject` set status = 'Completed' where name = %s", arg)
|
||||
return cstr('true')
|
||||
|
@ -2,7 +2,7 @@
|
||||
import webnotes
|
||||
|
||||
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, set_default, str_esc_quote, user_format, validate_email_add
|
||||
from webnotes.util.email_lib import sendmail
|
||||
from webnotes.utils.email_lib import sendmail
|
||||
from webnotes.model import db_exists
|
||||
from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType
|
||||
from webnotes.model.doclist import getlist, copy_doclist
|
||||
@ -70,22 +70,27 @@ class DocType:
|
||||
#--------------------------------------------
|
||||
|
||||
def on_update(self):
|
||||
if (self.doc.status =='Open') and (self.doc.task_email_notify==1):
|
||||
if (self.doc.allocated_to == self.doc.allocated_to_old):
|
||||
return
|
||||
else:
|
||||
self.doc.allocated_to_old = self.doc.allocated_to
|
||||
msg2="""A task %s has been assigned to you by %s on %s<br/><br/>Project: %s <br/><br/> \
|
||||
Review Date: %s<br/><br/>Closing Date: %s <br/><br/>Details: %s""" \
|
||||
%(self.doc.name, self.doc.senders_name, self.doc.opening_date, \
|
||||
self.doc.project, self.doc.review_date, self.doc.closing_date, self.doc.description)
|
||||
if self.doc.status =='Open' and self.doc.allocated_to:
|
||||
if self.doc.task_email_notify==1:
|
||||
if (self.doc.allocated_to == self.doc.allocated_to_old):
|
||||
return
|
||||
else:
|
||||
self.doc.allocated_to_old = self.doc.allocated_to
|
||||
msg2="""This is an auto generated email.<br/>A task %s has been assigned to you by %s on %s<br/><br/>\
|
||||
Project: %s <br/><br/>Review Date: %s<br/><br/>Closing Date: %s <br/><br/>Details: %s <br/><br/>""" \
|
||||
%(self.doc.name, self.doc.senders_name, self.doc.opening_date, \
|
||||
self.doc.project, self.doc.review_date, self.doc.closing_date, self.doc.description)
|
||||
sendmail(self.doc.allocated_to, sender='automail@webnotestech.com', msg=msg2,send_now=1,\
|
||||
subject='A task has been assigned')
|
||||
self.doc.sent_reminder=0
|
||||
if self.doc.exp_start_date:
|
||||
sql("delete from tabEvent where ref_type='Task' and ref_name=%s", self.doc.name)
|
||||
self.add_calendar_event()
|
||||
sendmail(self.doc.allocated_to, sender='automail@webnotestech.com',subject='A task has been assigned',\
|
||||
parts=[['text/plain',msg2]])
|
||||
self.doc.sent_reminder=0
|
||||
pass
|
||||
#Function to be called from server inside scheduler ... set reminder/events
|
||||
#validate before sending for approval
|
||||
else:
|
||||
msgprint("An Expeted start date has not been set for this task.Please set a, 'Expected Start date'\
|
||||
to add an event to allocated persons calender.You can save a task without this also.")
|
||||
pass
|
||||
|
||||
def validate_for_pending_review(self):
|
||||
if not self.doc.allocated_to:
|
||||
msgprint("Please enter allocated_to.")
|
||||
@ -163,10 +168,13 @@ class DocType:
|
||||
self.validate_for_closed()
|
||||
self.doc.closing_date = nowdate()
|
||||
set(self.doc, 'status', 'Closed')
|
||||
self.remove_event_from_calender()
|
||||
set(self.doc, 'docstatus', 1)
|
||||
self.doc.save()
|
||||
return cstr('true')
|
||||
|
||||
def remove_event_from_calender():
|
||||
sql("delete from tabEvent where ref_type='Task' and ref_name=%s", self.doc.name)
|
||||
self.doc.save()
|
||||
def cancel_task(self):
|
||||
chk = sql("select distinct t1.name from `tabTimesheet` t1, `tabTimesheet Detail` t2 where t2.parent = t1.name and t2.task_id = %s and t1.status!='Cancelled'", self.doc.name)
|
||||
if chk:
|
||||
@ -178,22 +186,17 @@ class DocType:
|
||||
set(self.doc, 'docstatus', 2)
|
||||
self.doc.save()
|
||||
return cstr('true')
|
||||
# def delete_event_from_calender(self): Add later
|
||||
|
||||
|
||||
def add_calendar_event(self):
|
||||
in_calendar_of = self.doc.allocated_to
|
||||
event = Document('Event')
|
||||
event.owner = in_calendar_of
|
||||
event.description =''
|
||||
#'Task:%s <br/> By:%s <br/> Project:%s <br/>Details:%s' \
|
||||
#%(self.doc.name,self.doc.senders_name,self.doc.project,self.doc.details)
|
||||
event.event_date = self.doc.exp_start_date
|
||||
event.event_hour = self.doc.exp_total_hrs and exp_total_hrs or ''
|
||||
event.event_date = self.doc.exp_start_date and self.doc.exp_start_date or ''
|
||||
event.event_hour = '10:00'
|
||||
event.event_type = 'Private'
|
||||
event.ref_type = 'Task'
|
||||
event.ref_name = self.doc.name
|
||||
event.save(1)
|
||||
|
||||
|
||||
def on_cancel(self):
|
||||
self.cancel_task()
|
||||
|
@ -5,14 +5,14 @@
|
||||
{
|
||||
'creation': '2011-01-28 17:52:35',
|
||||
'docstatus': 0,
|
||||
'modified': '2011-12-21 17:22:20',
|
||||
'modified': '2011-12-22 14:31:07',
|
||||
'modified_by': 'Administrator',
|
||||
'owner': 'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all DocType
|
||||
{
|
||||
'_last_update': '1324465350',
|
||||
'_last_update': '1324468340',
|
||||
'allow_trash': 1,
|
||||
'autoname': 'TIC/.####',
|
||||
'colour': 'White:FFF',
|
||||
@ -26,7 +26,7 @@
|
||||
'show_in_menu': 0,
|
||||
'subject': '%(subject)s',
|
||||
'tag_fields': 'status',
|
||||
'version': 248
|
||||
'version': 250
|
||||
},
|
||||
|
||||
# These values are common for all DocField
|
||||
@ -256,6 +256,7 @@
|
||||
'fieldtype': 'Link',
|
||||
'hidden': 1,
|
||||
'label': 'Allocated To Old',
|
||||
'no_copy': 1,
|
||||
'permlevel': 0
|
||||
},
|
||||
|
||||
@ -285,6 +286,17 @@
|
||||
'permlevel': 0
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'sent_reminder',
|
||||
'fieldtype': 'Date',
|
||||
'hidden': 1,
|
||||
'label': 'Sent Reminder',
|
||||
'no_copy': 1,
|
||||
'permlevel': 0
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': 'DocField',
|
||||
|
Loading…
x
Reference in New Issue
Block a user