timesheet fix

This commit is contained in:
Rushabh Mehta 2013-01-16 07:47:33 +05:30
parent 390f4e9475
commit c0f2e6dd23

View File

@ -16,6 +16,7 @@
from __future__ import unicode_literals
import webnotes
import time, datetime
from webnotes.utils import cint, cstr, getdate, now, nowdate
from webnotes.model import db_exists
@ -24,8 +25,6 @@ from webnotes import msgprint
sql = webnotes.conn.sql
class DocType:
def __init__(self,doc,doclist=[]):
self.doc = doc
@ -43,6 +42,14 @@ class DocType:
ret = {'task_id': tsk and tsk[0][0] or '', 'project_name': tsk and tsk[0][1] or '', 'customer_name': tsk and tsk[0][3] or ''}
return ret
def get_time(self, timestr):
if len(timestr.split(":"))==2:
format = "%H:%M"
else:
format = "%H:%M:%S"
return time.strptime(timestr, format)
def validate(self):
if getdate(self.doc.timesheet_date) > getdate(nowdate()):
msgprint("You can not prepare timesheet for future date")
@ -53,11 +60,10 @@ class DocType:
msgprint("You have already created timesheet "+ cstr(chk and chk[0][0] or '')+" for this date.")
raise Exception
import time
for d in getlist(self.doclist, 'timesheet_details'):
if d.act_start_time and d.act_end_time:
d1 = time.strptime(d.act_start_time, "%H:%M")
d2 = time.strptime(d.act_end_time, "%H:%M")
d1 = self.get_time(d.act_start_time)
d2 = self.get_time(d.act_end_time)
if d1 > d2:
msgprint("Start time can not be greater than end time. Check for Task Id : "+cstr(d.task_id))
@ -67,8 +73,6 @@ class DocType:
raise Exception
def calculate_total_hr(self):
import datetime
import time
for d in getlist(self.doclist, 'timesheet_details'):
x1 = d.act_start_time.split(":")
x2 = d.act_end_time.split(":")
@ -76,7 +80,7 @@ class DocType:
d1 = datetime.timedelta(minutes=cint(x1[1]), hours=cint(x1[0]))
d2 = datetime.timedelta(minutes=cint(x2[1]), hours=cint(x2[0]))
d3 = (d2 - d1).seconds
d.act_total_hrs = time.strftime("%H:%M", time.gmtime(d3))
d.act_total_hrs = time.strftime("%H:%M:%S", time.gmtime(d3))
sql("update `tabTimesheet Detail` set act_total_hrs = %s where parent=%s and name=%s", (d.act_total_hrs,self.doc.name,d.name))
def on_update(self):