update
This commit is contained in:
		
							parent
							
								
									7e812bbee0
								
							
						
					
					
						commit
						8acb043a8a
					
				| @ -1,12 +1,14 @@ | |||||||
| # Please edit this list and import only required elements | # Please edit this list and import only required elements | ||||||
| import webnotes | 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, sendmail, set_default, str_esc_quote, user_format, validate_email_add | 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.model import db_exists | from webnotes.model import db_exists | ||||||
| from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType | from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType | ||||||
| from webnotes.model.doclist import getlist, copy_doclist | from webnotes.model.doclist import getlist, copy_doclist | ||||||
| from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax | from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax | ||||||
| from webnotes import session, form, is_testing, msgprint, errprint | from webnotes import session, form, is_testing, msgprint, errprint | ||||||
|  | 
 | ||||||
| sql = webnotes.conn.sql | sql = webnotes.conn.sql | ||||||
| set = webnotes.conn.set | set = webnotes.conn.set | ||||||
| get_value = webnotes.conn.get_value | get_value = webnotes.conn.get_value | ||||||
| @ -15,161 +17,183 @@ get_value = webnotes.conn.get_value | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class DocType: | class DocType: | ||||||
|   def __init__(self,doc,doclist=[]): | 	def __init__(self,doc,doclist=[]): | ||||||
|     self.doc = doc | 		self.doc = doc | ||||||
|     self.doclist = doclist | 		self.doclist = doclist | ||||||
| 	 | 	 | ||||||
|   def get_project_details(self): | 	def get_project_details(self): | ||||||
|     cust = sql("select customer, customer_name from `tabProject` where name = %s", self.doc.project) | 		cust = sql("select customer, customer_name from `tabProject` where name = %s", self.doc.project) | ||||||
|     if cust: | 		if cust: | ||||||
|       ret = {'customer': cust and cust[0][0] or '', 'customer_name': cust and cust[0][1] or ''} | 			ret = {'customer': cust and cust[0][0] or '', 'customer_name': cust and cust[0][1] or ''} | ||||||
|       return ret | 			return ret | ||||||
| 	 | 	 | ||||||
|   def get_customer_details(self): | 	def get_customer_details(self): | ||||||
|     cust = sql("select customer_name from `tabCustomer` where name=%s", self.doc.customer) | 		cust = sql("select customer_name from `tabCustomer` where name=%s", self.doc.customer) | ||||||
|     if cust: | 		if cust: | ||||||
|       ret = {'customer_name': cust and cust[0][0] or ''} | 			ret = {'customer_name': cust and cust[0][0] or ''} | ||||||
|       return ret | 			return ret | ||||||
| 	 | 	 | ||||||
|   def get_allocated_to_name(self): | 	def get_allocated_to_name(self): | ||||||
|     as_em = sql("select first_name, last_name from `tabProfile` where name=%s",str(self.doc.allocated_to)) | 		as_em = sql("select first_name, last_name from `tabProfile` where name=%s",str(self.doc.allocated_to)) | ||||||
|     ret = { 'allocated_to_name' : as_em and (as_em[0][0] + ' ' + as_em[0][1]) or ''} | 		ret = { 'allocated_to_name' : as_em and (as_em[0][0] + ' ' + as_em[0][1]) or ''} | ||||||
|     return ret | 		return ret | ||||||
| 
 | 
 | ||||||
|   # validate | 	# validate | ||||||
|   #--------------------------------------------    | 	#--------------------------------------------	  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   def validate(self): | 	def validate(self): | ||||||
|     if not self.doc.opening_date: | 		if not self.doc.opening_date: | ||||||
|       msgprint("Please enter Opening Date.") | 			msgprint("Please enter Opening Date.") | ||||||
|       raise Exception | 			raise Exception | ||||||
|     elif getdate(self.doc.opening_date) > getdate(nowdate()): | 		elif getdate(self.doc.opening_date) > getdate(nowdate()): | ||||||
|       msgprint("Opening date can not be future date") | 			msgprint("Opening date can not be future date") | ||||||
|       raise Exception | 			raise Exception | ||||||
| 		 | 		 | ||||||
|     if self.doc.exp_start_date and self.doc.exp_end_date and getdate(self.doc.exp_start_date) > getdate(self.doc.exp_end_date): | 		if self.doc.exp_start_date and self.doc.exp_end_date and getdate(self.doc.exp_start_date) > getdate(self.doc.exp_end_date): | ||||||
|       msgprint("'Expected Start Date' can not be greater than 'Expected End Date'") | 			msgprint("'Expected Start Date' can not be greater than 'Expected End Date'") | ||||||
|       raise Exception | 			raise Exception | ||||||
| 		 | 		 | ||||||
|     if self.doc.act_start_date and self.doc.act_end_date and getdate(self.doc.act_start_date) > getdate(self.doc.act_end_date): | 		if self.doc.act_start_date and self.doc.act_end_date and getdate(self.doc.act_start_date) > getdate(self.doc.act_end_date): | ||||||
|       msgprint("'Actual Start Date' can not be greater than 'Actual End Date'") | 			msgprint("'Actual Start Date' can not be greater than 'Actual End Date'") | ||||||
|       raise Exception | 			raise Exception | ||||||
| 		 | 		 | ||||||
|     if self.doc.opening_date and self.doc.review_date and getdate(self.doc.opening_date) > getdate(self.doc.review_date): | 		if self.doc.opening_date and self.doc.review_date and getdate(self.doc.opening_date) > getdate(self.doc.review_date): | ||||||
|       msgprint("Review Date should be greater than or equal to Opening Date ") | 			msgprint("Review Date should be greater than or equal to Opening Date ") | ||||||
|       raise Exception | 			raise Exception | ||||||
| 		 | 		 | ||||||
|     if self.doc.closing_date and self.doc.review_date and getdate(self.doc.closing_date) < getdate(self.doc.review_date): | 		if self.doc.closing_date and self.doc.review_date and getdate(self.doc.closing_date) < getdate(self.doc.review_date): | ||||||
|       msgprint("Closing Date should be greater than or equal to Review Date ") | 			msgprint("Closing Date should be greater than or equal to Review Date ") | ||||||
|       raise Exception | 			raise Exception | ||||||
| 
 | 
 | ||||||
|   # on update | 	# on update | ||||||
|   #--------------------------------------------    | 	#--------------------------------------------	  | ||||||
| 	 | 	 | ||||||
|   def on_update(self): | 	def on_update(self): | ||||||
|     if (self.doc.status =='Open') and (self.doc.task_email_notify==1): | 		if (self.doc.status =='Open') and (self.doc.task_email_notify==1): | ||||||
|        	msg2= 'A task %s has been assigned to you by %s on %s <br/> \ | 			if (self.doc.allocated_to == self.doc.allocated_to_old): | ||||||
|        	Project:%s <br/> Review Date:%s <br /> Closing Date:%s <br /> Details  %s' \ | 				return			 		 | ||||||
|        	%(self.doc.name,self.doc.senders_name,self.doc.opening_date,self.doc.project, \ | 			else: | ||||||
|        	self.doc.review_date,self.doc.closing_date,self.doc.description) | 				self.doc.allocated_to_old = self.doc.allocated_to | ||||||
|     	sendmail(self.doc.allocated_to, sender='automail@webnotestech.com', \ | 				msg2="""A task %s has been assigned to you by %s on %s<br/><br/>Project: %s <br/><br/> \ | ||||||
|     	subject='A task has been assigned', parts=[['text/plain',msg2]]) | 				Review Date: %s<br/><br/>Closing Date: %s <br/><br/>Details: %s""" \ | ||||||
|     pass | 				%(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) | ||||||
|  | 				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 | ||||||
|  | 	def validate_for_pending_review(self): | ||||||
|  | 		if not self.doc.allocated_to: | ||||||
|  | 			msgprint("Please enter allocated_to.") | ||||||
|  | 			raise Exception | ||||||
|  | 		self.validate_with_timesheet_dates() | ||||||
| 	 | 	 | ||||||
|   #validate before sending for approval | 	#validate before closing task | ||||||
|   def validate_for_pending_review(self): | 	def validate_for_closed(self): | ||||||
|     if not self.doc.allocated_to: | 		self.check_non_submitted_timesheets() | ||||||
|       msgprint("Please enter allocated_to.") | 		self.get_actual_total_hrs() | ||||||
|       raise Exception |  | ||||||
|     self.validate_with_timesheet_dates() |  | ||||||
| 	 | 	 | ||||||
|   #validate before closing task | 	def check_non_submitted_timesheets(self): | ||||||
|   def validate_for_closed(self): | 		chk = sql("select t1.name from `tabTimesheet` t1, `tabTimesheet Detail` t2 where t2.parent=t1.name and t2.task_id=%s and t1.status='Draft'", self.doc.name) | ||||||
|     self.check_non_submitted_timesheets() | 		if chk: | ||||||
|     self.get_actual_total_hrs() | 			chk_lst = [x[0] for x in chk] | ||||||
|  | 			msgprint("Please submit timesheet(s) : "+','.join(chk_lst)+" before declaring this task as completed. As details of this task present in timesheet(s)") | ||||||
|  | 			raise Exception | ||||||
| 	 | 	 | ||||||
|   def check_non_submitted_timesheets(self): | 	#calculate actual total hours taken to complete task from timesheets | ||||||
|     chk = sql("select t1.name from `tabTimesheet` t1, `tabTimesheet Detail` t2 where t2.parent=t1.name and t2.task_id=%s and t1.status='Draft'", self.doc.name) | 	def get_actual_total_hrs(self): | ||||||
|     if chk: | 		import datetime | ||||||
|       chk_lst = [x[0] for x in chk] | 		import time | ||||||
|       msgprint("Please submit timesheet(s) : "+','.join(chk_lst)+" before declaring this task as completed. As details of this task present in timesheet(s)") | 		chk = sql("select t2.act_total_hrs from `tabTimesheet` t1, `tabTimesheet Detail` t2 where t2.parent = t1.name and t2.task_id = %s and t1.status = 'Submitted' and ifnull(t2.act_total_hrs, '')!='' order by t1.timesheet_date asc", self.doc.name) | ||||||
|       raise Exception | 		if chk: | ||||||
|  | 			chk_lst = [x[0] for x in chk] | ||||||
|  | 			actual_total = total =0 | ||||||
| 			 | 			 | ||||||
|   #calculate actual total hours taken to complete task from timesheets | 			for m in chk_lst: | ||||||
|   def get_actual_total_hrs(self): | 				m1, m2=[], 0 | ||||||
|     import datetime | 				m1 = m.split(":") | ||||||
|     import time | 				m2 = (datetime.timedelta(minutes=cint(m1[1]), hours=cint(m1[0]))).seconds | ||||||
|     chk = sql("select t2.act_total_hrs from `tabTimesheet` t1, `tabTimesheet Detail` t2 where t2.parent = t1.name and t2.task_id = %s and t1.status = 'Submitted' and ifnull(t2.act_total_hrs, '')!='' order by t1.timesheet_date asc", self.doc.name) | 				total = total + m2 | ||||||
|     if chk: |  | ||||||
|       chk_lst = [x[0] for x in chk] |  | ||||||
|       actual_total = total =0 |  | ||||||
| 			 | 			 | ||||||
|       for m in chk_lst: | 			actual_total = time.strftime("%H:%M", time.gmtime(total)) | ||||||
|         m1, m2=[], 0 | 			set(self.doc, 'act_total_hrs', actual_total) | ||||||
|         m1 = m.split(":") |  | ||||||
|         m2 = (datetime.timedelta(minutes=cint(m1[1]), hours=cint(m1[0]))).seconds |  | ||||||
|         total = total + m2 |  | ||||||
| 	 | 	 | ||||||
|       actual_total = time.strftime("%H:%M", time.gmtime(total)) | 	# validate and fetch actual start and end date | ||||||
|       set(self.doc, 'act_total_hrs', actual_total) | 	def validate_with_timesheet_dates(self): | ||||||
|  | 		chk = sql("select t1.name, t1.timesheet_date from `tabTimesheet` t1, `tabTimesheet Detail` t2 where t2.parent = t1.name and t2.task_id = %s and t1.status = 'Submitted' order by t1.timesheet_date asc", self.doc.name, as_dict=1) | ||||||
|  | 		if chk: | ||||||
|  | 			if self.doc.act_start_date: | ||||||
|  | 				if chk[0]['timesheet_date'] > getdate(self.doc.act_start_date) or chk[0]['timesheet_date'] < getdate(self.doc.act_start_date): | ||||||
|  | 					msgprint("Actual start date of this task is "+cstr(chk[0]['timesheet_date'])+" as per timesheet "+cstr(chk[0]['name'])) | ||||||
|  | 					raise Exception | ||||||
|  | 			else: | ||||||
|  | 				self.doc.act_start_date = chk[0]['timesheet_date'] | ||||||
| 			 | 			 | ||||||
|   # validate and fetch actual start and end date | 			if self.doc.act_end_date: | ||||||
|   def validate_with_timesheet_dates(self): | 				if chk[len(chk)-1]['timesheet_date'] < getdate(self.doc.act_end_date) or chk[len(chk)-1]['timesheet_date'] > getdate(self.doc.act_end_date): | ||||||
|     chk = sql("select t1.name, t1.timesheet_date from `tabTimesheet` t1, `tabTimesheet Detail` t2 where t2.parent = t1.name and t2.task_id = %s and t1.status = 'Submitted' order by t1.timesheet_date asc", self.doc.name, as_dict=1) | 					msgprint("Actual end date of this task is "+cstr(chk[len(chk)-1]['timesheet_date'])+" as per timesheet "+cstr(chk[len(chk)-1]['name'])) | ||||||
|     if chk: | 					raise Exception | ||||||
|       if self.doc.act_start_date: | 			else: | ||||||
|         if chk[0]['timesheet_date'] > getdate(self.doc.act_start_date) or chk[0]['timesheet_date'] < getdate(self.doc.act_start_date): | 				self.doc.act_end_date = chk[len(chk)-1]['timesheet_date'] | ||||||
|           msgprint("Actual start date of this task is "+cstr(chk[0]['timesheet_date'])+" as per timesheet "+cstr(chk[0]['name'])) |  | ||||||
|           raise Exception |  | ||||||
|       else: |  | ||||||
|         self.doc.act_start_date = chk[0]['timesheet_date'] |  | ||||||
| 	 | 	 | ||||||
|       if self.doc.act_end_date: | 	def set_for_review(self): | ||||||
|         if chk[len(chk)-1]['timesheet_date'] < getdate(self.doc.act_end_date) or chk[len(chk)-1]['timesheet_date'] > getdate(self.doc.act_end_date): | 		self.check_non_submitted_timesheets() | ||||||
|           msgprint("Actual end date of this task is "+cstr(chk[len(chk)-1]['timesheet_date'])+" as per timesheet "+cstr(chk[len(chk)-1]['name'])) | 		self.validate_for_pending_review() | ||||||
|           raise Exception | 		self.get_actual_total_hrs() | ||||||
|       else: | 		self.doc.review_date = nowdate() | ||||||
|         self.doc.act_end_date = chk[len(chk)-1]['timesheet_date'] | 		set(self.doc, 'status', 'Pending Review') | ||||||
|  | 		self.doc.save() | ||||||
|  | 		return cstr('true') | ||||||
| 	 | 	 | ||||||
|   def set_for_review(self): | 	def reopen_task(self): | ||||||
|     self.check_non_submitted_timesheets() | 		set(self.doc, 'status', 'Open') | ||||||
|     self.validate_for_pending_review() | 		self.doc.save() | ||||||
|     self.get_actual_total_hrs() | 		return cstr('true') | ||||||
|     self.doc.review_date = nowdate() |  | ||||||
|     set(self.doc, 'status', 'Pending Review') |  | ||||||
|     self.doc.save() |  | ||||||
|     return cstr('true') |  | ||||||
| 	 | 	 | ||||||
|   def reopen_task(self): | 	def declare_completed(self): | ||||||
|     set(self.doc, 'status', 'Open') | 		if self.doc.status == 'Open': | ||||||
|     self.doc.save() | 			self.validate_for_pending_review() | ||||||
|     return cstr('true') | 			self.doc.review_date = nowdate() | ||||||
|  | 		else: | ||||||
|  | 			self.validate_with_timesheet_dates() | ||||||
|  | 		self.validate_for_closed() | ||||||
|  | 		self.doc.closing_date = nowdate() | ||||||
|  | 		set(self.doc, 'status', 'Closed') | ||||||
|  | 		set(self.doc, 'docstatus', 1) | ||||||
|  | 		self.doc.save() | ||||||
|  | 		return cstr('true') | ||||||
| 	 | 	 | ||||||
|   def declare_completed(self): | 	def cancel_task(self): | ||||||
|     if self.doc.status == 'Open': | 		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) | ||||||
|       self.validate_for_pending_review() | 		if chk: | ||||||
|       self.doc.review_date = nowdate() | 			chk_lst = [x[0] for x in chk] | ||||||
|     else: | 			msgprint("Timesheet(s) "+','.join(chk_lst)+" created against this task. Thus can not be cancelled") | ||||||
|       self.validate_with_timesheet_dates() | 			raise Exception | ||||||
|     self.validate_for_closed() | 		else: | ||||||
|     self.doc.closing_date = nowdate() | 			set(self.doc, 'status', 'Cancelled') | ||||||
|     set(self.doc, 'status', 'Closed') | 			set(self.doc, 'docstatus', 2) | ||||||
|     set(self.doc, 'docstatus', 1) | 		self.doc.save() | ||||||
|     self.doc.save() | 		return cstr('true') | ||||||
|     return cstr('true') | 	# def delete_event_from_calender(self): Add later | ||||||
| 	 | 	 | ||||||
|   def cancel_task(self): | 	def add_calendar_event(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) | 		in_calendar_of = self.doc.allocated_to | ||||||
|     if chk: | 		event = Document('Event') | ||||||
|       chk_lst = [x[0] for x in chk] | 		event.owner = in_calendar_of | ||||||
|       msgprint("Timesheet(s) "+','.join(chk_lst)+" created against this task. Thus can not be cancelled") | 		event.description =''  | ||||||
|       raise Exception | 		#'Task:%s <br/> By:%s <br/> Project:%s <br/>Details:%s' \ | ||||||
|     else: | 		#%(self.doc.name,self.doc.senders_name,self.doc.project,self.doc.details) | ||||||
|       set(self.doc, 'status', 'Cancelled') | 		event.event_date = self.doc.exp_start_date | ||||||
|       set(self.doc, 'docstatus', 2) | 		event.event_hour = self.doc.exp_total_hrs and exp_total_hrs or '' | ||||||
|     self.doc.save() | 		event.event_type = 'Private' | ||||||
|     return cstr('true') | 		event.ref_type = 'Task' | ||||||
|  | 		event.ref_name = self.doc.name | ||||||
|  | 		event.save(1) | ||||||
| 
 | 
 | ||||||
|   def on_cancel(self): | 		 | ||||||
|     self.cancel_task() | 	def on_cancel(self): | ||||||
|  | 		self.cancel_task() | ||||||
|  | |||||||
| @ -5,14 +5,14 @@ | |||||||
| 	{ | 	{ | ||||||
| 		'creation': '2011-01-28 17:52:35', | 		'creation': '2011-01-28 17:52:35', | ||||||
| 		'docstatus': 0, | 		'docstatus': 0, | ||||||
| 		'modified': '2011-12-21 16:32:30', | 		'modified': '2011-12-21 17:22:20', | ||||||
| 		'modified_by': 'Administrator', | 		'modified_by': 'Administrator', | ||||||
| 		'owner': 'Administrator' | 		'owner': 'Administrator' | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
| 	# These values are common for all DocType | 	# These values are common for all DocType | ||||||
| 	{ | 	{ | ||||||
| 		'_last_update': '1324394580', | 		'_last_update': '1324465350', | ||||||
| 		'allow_trash': 1, | 		'allow_trash': 1, | ||||||
| 		'autoname': 'TIC/.####', | 		'autoname': 'TIC/.####', | ||||||
| 		'colour': 'White:FFF', | 		'colour': 'White:FFF', | ||||||
| @ -26,7 +26,7 @@ | |||||||
| 		'show_in_menu': 0, | 		'show_in_menu': 0, | ||||||
| 		'subject': '%(subject)s', | 		'subject': '%(subject)s', | ||||||
| 		'tag_fields': 'status', | 		'tag_fields': 'status', | ||||||
| 		'version': 247 | 		'version': 248 | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
| 	# These values are common for all DocField | 	# These values are common for all DocField | ||||||
| @ -249,6 +249,16 @@ | |||||||
| 		'width': '50%' | 		'width': '50%' | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
|  | 	# DocField | ||||||
|  | 	{ | ||||||
|  | 		'doctype': 'DocField', | ||||||
|  | 		'fieldname': 'allocated_to_old', | ||||||
|  | 		'fieldtype': 'Link', | ||||||
|  | 		'hidden': 1, | ||||||
|  | 		'label': 'Allocated To Old', | ||||||
|  | 		'permlevel': 0 | ||||||
|  | 	}, | ||||||
|  | 
 | ||||||
| 	# DocField | 	# DocField | ||||||
| 	{ | 	{ | ||||||
| 		'colour': 'White:FFF', | 		'colour': 'White:FFF', | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user