[FIX] hr_attendance:improved 'Attendance by month' and 'Weekly Attendance' report by changing the code into float
lp bug: https://launchpad.net/bugs/711533 fixed bzr revid: mtr@mtr-20110207093621-6r52uwthtmc08wk7
This commit is contained in:
@@ -34,10 +34,10 @@ from tools import ustr
|
||||
one_day = relativedelta(days=1)
|
||||
month2name = [0, 'January', 'February', 'March', 'April', 'May', 'Jun', 'July', 'August', 'September', 'October', 'November', 'December']
|
||||
|
||||
#def hour2str(h):
|
||||
# hours = int(h)
|
||||
# minutes = int(round((h - hours) * 60, 0))
|
||||
# return '%02dh%02d' % (hours, minutes)
|
||||
def hour2str(h):
|
||||
hours = int(h)
|
||||
minutes = int(round((h - hours) * 60, 0))
|
||||
return '%02dh%02d' % (hours, minutes)
|
||||
|
||||
def lengthmonth(year, month):
|
||||
if month == 2 and ((year % 4 == 0) and ((year % 100 != 0) or (year % 400 == 0))):
|
||||
@@ -85,18 +85,12 @@ class report_custom(report_rml):
|
||||
for att in attendences:
|
||||
dt = datetime.strptime(att['name'], '%Y-%m-%d %H:%M:%S')
|
||||
if ldt and att['action'] == 'sign_out':
|
||||
tot_time = (dt - ldt).seconds
|
||||
hrs, remainder = divmod(tot_time, 3600)
|
||||
min, sec = divmod(remainder, 60)
|
||||
if min < 10:
|
||||
wh += float((str(hrs))+ '.' + '0' +(str(min)))
|
||||
else:
|
||||
wh += float((str(hrs))+ '.' + (str(min)))
|
||||
wh += (float((dt - ldt).seconds)/60/60)
|
||||
else:
|
||||
ldt = dt
|
||||
# Week xml representation
|
||||
# wh = hour2str(wh)
|
||||
today_xml = '<day num="%s"><wh>%s</wh></day>' % ((today - month).days+1, round(wh,2))
|
||||
wh = hour2str(wh)
|
||||
today_xml = '<day num="%s"><wh>%s</wh></day>' % ((today - month).days+1, (wh))
|
||||
dy=(today - month).days+1
|
||||
days_xml.append(today_xml)
|
||||
today, tomor = tomor, tomor + one_day
|
||||
|
||||
@@ -84,14 +84,7 @@ class report_custom(report_rml):
|
||||
for att in attendances:
|
||||
dt = datetime.strptime(att['name'], '%Y-%m-%d %H:%M:%S')
|
||||
if ldt and att['action'] == 'sign_out':
|
||||
tot_time = (dt - ldt).seconds
|
||||
hrs, remainder = divmod(tot_time, 3600)
|
||||
min, sec = divmod(remainder, 60)
|
||||
if min < 10:
|
||||
wh = float((str(hrs))+ '.' + '0' +(str(min)))
|
||||
else:
|
||||
wh = float((str(hrs))+ '.' + (str(min)))
|
||||
week_wh[ldt.date().weekday()] = week_wh.get(ldt.date().weekday(), 0) + round(wh,2)
|
||||
week_wh[ldt.date().weekday()] = week_wh.get(ldt.date().weekday(), 0) + (float((dt - ldt).seconds)/3600)
|
||||
else:
|
||||
ldt = dt
|
||||
|
||||
@@ -100,10 +93,10 @@ class report_custom(report_rml):
|
||||
for idx in range(7):
|
||||
week_repr.append('<%s>' % num2day[idx])
|
||||
if idx in week_wh:
|
||||
week_repr.append('<workhours>%s</workhours>' %(str(week_wh[idx])).replace('.','h'))
|
||||
week_repr.append('<workhours>%sh%02d</workhours>' % to_hour(week_wh[idx]))
|
||||
week_repr.append('</%s>' % num2day[idx])
|
||||
week_repr.append('<total>')
|
||||
week_repr.append('<worked>%s</worked>' % str(sum(week_wh.values())).replace('.','h'))
|
||||
week_repr.append('<worked>%sh%02d</worked>' % to_hour(reduce(lambda x,y:x+y, week_wh.values(), 0)))
|
||||
week_repr.append('</total>')
|
||||
week_repr.append('</week>')
|
||||
if len(week_repr) > 21: # 21 = minimal length of week_repr
|
||||
|
||||
Reference in New Issue
Block a user