timesheet fix
This commit is contained in:
parent
390f4e9475
commit
c0f2e6dd23
@ -8,14 +8,15 @@
|
|||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
|
import time, datetime
|
||||||
|
|
||||||
from webnotes.utils import cint, cstr, getdate, now, nowdate
|
from webnotes.utils import cint, cstr, getdate, now, nowdate
|
||||||
from webnotes.model import db_exists
|
from webnotes.model import db_exists
|
||||||
@ -24,67 +25,70 @@ from webnotes import msgprint
|
|||||||
|
|
||||||
sql = webnotes.conn.sql
|
sql = webnotes.conn.sql
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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_customer_details(self, project_name):
|
def get_customer_details(self, project_name):
|
||||||
cust = sql("select customer, customer_name from `tabProject` where name = %s", project_name)
|
cust = sql("select customer, customer_name from `tabProject` where name = %s", project_name)
|
||||||
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_task_details(self, task_sub):
|
def get_task_details(self, task_sub):
|
||||||
tsk = sql("select name, project, customer, customer_name from `tabTask` where subject = %s", task_sub)
|
tsk = sql("select name, project, customer, customer_name from `tabTask` where subject = %s", task_sub)
|
||||||
if tsk:
|
if tsk:
|
||||||
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 ''}
|
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
|
return ret
|
||||||
|
|
||||||
def validate(self):
|
def get_time(self, timestr):
|
||||||
if getdate(self.doc.timesheet_date) > getdate(nowdate()):
|
if len(timestr.split(":"))==2:
|
||||||
msgprint("You can not prepare timesheet for future date")
|
format = "%H:%M"
|
||||||
raise Exception
|
else:
|
||||||
|
format = "%H:%M:%S"
|
||||||
|
|
||||||
chk = sql("select name from `tabTimesheet` where timesheet_date=%s and owner=%s and status!='Cancelled' and name!=%s", (self.doc.timesheet_date, self.doc.owner, self.doc.name))
|
return time.strptime(timestr, format)
|
||||||
if chk:
|
|
||||||
msgprint("You have already created timesheet "+ cstr(chk and chk[0][0] or '')+" for this date.")
|
|
||||||
raise Exception
|
|
||||||
|
|
||||||
import time
|
def validate(self):
|
||||||
for d in getlist(self.doclist, 'timesheet_details'):
|
if getdate(self.doc.timesheet_date) > getdate(nowdate()):
|
||||||
if d.act_start_time and d.act_end_time:
|
msgprint("You can not prepare timesheet for future date")
|
||||||
d1 = time.strptime(d.act_start_time, "%H:%M")
|
raise Exception
|
||||||
d2 = time.strptime(d.act_end_time, "%H:%M")
|
|
||||||
|
|
||||||
if d1 > d2:
|
chk = sql("select name from `tabTimesheet` where timesheet_date=%s and owner=%s and status!='Cancelled' and name!=%s", (self.doc.timesheet_date, self.doc.owner, self.doc.name))
|
||||||
msgprint("Start time can not be greater than end time. Check for Task Id : "+cstr(d.task_id))
|
if chk:
|
||||||
raise Exception
|
msgprint("You have already created timesheet "+ cstr(chk and chk[0][0] or '')+" for this date.")
|
||||||
elif d1 == d2:
|
raise Exception
|
||||||
msgprint("Start time and end time can not be same. Check for Task Id : "+cstr(d.task_id))
|
|
||||||
raise Exception
|
|
||||||
|
|
||||||
def calculate_total_hr(self):
|
for d in getlist(self.doclist, 'timesheet_details'):
|
||||||
import datetime
|
if d.act_start_time and d.act_end_time:
|
||||||
import time
|
d1 = self.get_time(d.act_start_time)
|
||||||
for d in getlist(self.doclist, 'timesheet_details'):
|
d2 = self.get_time(d.act_end_time)
|
||||||
x1 = d.act_start_time.split(":")
|
|
||||||
x2 = d.act_end_time.split(":")
|
|
||||||
|
|
||||||
d1 = datetime.timedelta(minutes=cint(x1[1]), hours=cint(x1[0]))
|
if d1 > d2:
|
||||||
d2 = datetime.timedelta(minutes=cint(x2[1]), hours=cint(x2[0]))
|
msgprint("Start time can not be greater than end time. Check for Task Id : "+cstr(d.task_id))
|
||||||
d3 = (d2 - d1).seconds
|
raise Exception
|
||||||
d.act_total_hrs = time.strftime("%H:%M", time.gmtime(d3))
|
elif d1 == d2:
|
||||||
sql("update `tabTimesheet Detail` set act_total_hrs = %s where parent=%s and name=%s", (d.act_total_hrs,self.doc.name,d.name))
|
msgprint("Start time and end time can not be same. Check for Task Id : "+cstr(d.task_id))
|
||||||
|
raise Exception
|
||||||
|
|
||||||
def on_update(self):
|
def calculate_total_hr(self):
|
||||||
self.calculate_total_hr()
|
for d in getlist(self.doclist, 'timesheet_details'):
|
||||||
webnotes.conn.set(self.doc, 'status', 'Draft')
|
x1 = d.act_start_time.split(":")
|
||||||
|
x2 = d.act_end_time.split(":")
|
||||||
|
|
||||||
def on_submit(self):
|
d1 = datetime.timedelta(minutes=cint(x1[1]), hours=cint(x1[0]))
|
||||||
webnotes.conn.set(self.doc, 'status', 'Submitted')
|
d2 = datetime.timedelta(minutes=cint(x2[1]), hours=cint(x2[0]))
|
||||||
|
d3 = (d2 - d1).seconds
|
||||||
|
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_cancel(self):
|
def on_update(self):
|
||||||
webnotes.conn.set(self.doc, 'status', 'Cancelled')
|
self.calculate_total_hr()
|
||||||
|
webnotes.conn.set(self.doc, 'status', 'Draft')
|
||||||
|
|
||||||
|
def on_submit(self):
|
||||||
|
webnotes.conn.set(self.doc, 'status', 'Submitted')
|
||||||
|
|
||||||
|
def on_cancel(self):
|
||||||
|
webnotes.conn.set(self.doc, 'status', 'Cancelled')
|
Loading…
x
Reference in New Issue
Block a user