diff --git a/addons/hr_attendance/report/attendance_by_month.py b/addons/hr_attendance/report/attendance_by_month.py index 069c1adad88..2b708434317 100644 --- a/addons/hr_attendance/report/attendance_by_month.py +++ b/addons/hr_attendance/report/attendance_by_month.py @@ -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 = '%s' % ((today - month).days+1, round(wh,2)) + wh = hour2str(wh) + today_xml = '%s' % ((today - month).days+1, (wh)) dy=(today - month).days+1 days_xml.append(today_xml) today, tomor = tomor, tomor + one_day diff --git a/addons/hr_attendance/report/timesheet.py b/addons/hr_attendance/report/timesheet.py index de5bf225b4d..7203b7d4f1d 100644 --- a/addons/hr_attendance/report/timesheet.py +++ b/addons/hr_attendance/report/timesheet.py @@ -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('%s' %(str(week_wh[idx])).replace('.','h')) + week_repr.append('%sh%02d' % to_hour(week_wh[idx])) week_repr.append('' % num2day[idx]) week_repr.append('') - week_repr.append('%s' % str(sum(week_wh.values())).replace('.','h')) + week_repr.append('%sh%02d' % to_hour(reduce(lambda x,y:x+y, week_wh.values(), 0))) week_repr.append('') week_repr.append('') if len(week_repr) > 21: # 21 = minimal length of week_repr