From 94c626ed9ae08d3fcb7fe1fc54918673867d535d Mon Sep 17 00:00:00 2001 From: mtr Date: Thu, 3 Feb 2011 15:47:17 +0530 Subject: [PATCH 1/5] [FIX] hr_attendance:Attendance by month report now prints minutes also lp bug: https://launchpad.net/bugs/711533 fixed bzr revid: mtr@mtr-20110203101717-2hr3a3q83fto442h --- addons/hr_attendance/report/attendance_by_month.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/hr_attendance/report/attendance_by_month.py b/addons/hr_attendance/report/attendance_by_month.py index ced701ac661..7087256646e 100644 --- a/addons/hr_attendance/report/attendance_by_month.py +++ b/addons/hr_attendance/report/attendance_by_month.py @@ -85,7 +85,14 @@ 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': - wh += (dt - ldt).seconds/60/60 + tot_tim = (str(float((dt - ldt).seconds)/3600)) + hrs = int(tot_tim.split('.')[0]) + mints = int(tot_tim.split('.')[1]) + tot_min = (int(mints * 60) / 10) + if tot_min < (10) or tot_tim < ('0.09'): + wh += float((str(hrs))+ '.' + '0' +(str(tot_min))) + else: + wh += float((str(hrs))+ '.' + (str(tot_min))) else: ldt = dt # Week xml representation From 90fe3e95fe81acec181ebdf8c6e9d46686191c9a Mon Sep 17 00:00:00 2001 From: mtr Date: Fri, 4 Feb 2011 14:17:25 +0530 Subject: [PATCH 2/5] [FIX] hr_attendance:'Attendance by month' and 'Weekly Attendance' report now prints minutes also lp bug: https://launchpad.net/bugs/711533 fixed bzr revid: mtr@mtr-20110204084725-y2kjj4arrnv62zds --- .../hr_attendance/report/attendance_by_month.py | 15 +++++++-------- addons/hr_attendance/report/timesheet.py | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/addons/hr_attendance/report/attendance_by_month.py b/addons/hr_attendance/report/attendance_by_month.py index 7087256646e..069c1adad88 100644 --- a/addons/hr_attendance/report/attendance_by_month.py +++ b/addons/hr_attendance/report/attendance_by_month.py @@ -85,14 +85,13 @@ 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_tim = (str(float((dt - ldt).seconds)/3600)) - hrs = int(tot_tim.split('.')[0]) - mints = int(tot_tim.split('.')[1]) - tot_min = (int(mints * 60) / 10) - if tot_min < (10) or tot_tim < ('0.09'): - wh += float((str(hrs))+ '.' + '0' +(str(tot_min))) - else: - wh += float((str(hrs))+ '.' + (str(tot_min))) + 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))) else: ldt = dt # Week xml representation diff --git a/addons/hr_attendance/report/timesheet.py b/addons/hr_attendance/report/timesheet.py index 1ca7eeb584a..77196c4f0ae 100644 --- a/addons/hr_attendance/report/timesheet.py +++ b/addons/hr_attendance/report/timesheet.py @@ -43,7 +43,7 @@ class report_custom(report_rml): end_date = datetime.strptime(datas['form']['end_date'], '%Y-%m-%d') first_monday = start_date - relativedelta(days=start_date.date().weekday()) last_monday = end_date + relativedelta(days=7 - end_date.date().weekday()) - + if last_monday < first_monday: first_monday, last_monday = last_monday, first_monday @@ -80,10 +80,18 @@ class report_custom(report_rml): attendances.append({'name': n_monday.strftime('%Y-%m-%d %H:%M:%S'), 'action': 'sign_out'}) # sum up the attendances' durations ldt = None + wh = 0.0 for att in attendances: dt = datetime.strptime(att['name'], '%Y-%m-%d %H:%M:%S') if ldt and att['action'] == 'sign_out': - week_wh[ldt.date().weekday()] = week_wh.get(ldt.date().weekday(), 0) + ((dt - ldt).seconds/3600) + 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) else: ldt = dt @@ -92,10 +100,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('%sh%02d' % to_hour(week_wh[idx])) + week_repr.append('%s' %(week_wh[idx])) week_repr.append('' % num2day[idx]) week_repr.append('') - week_repr.append('%sh%02d' % to_hour(reduce(lambda x,y:x+y, week_wh.values(), 0))) + week_repr.append('%s' % sum(week_wh.values())) week_repr.append('') week_repr.append('') if len(week_repr) > 21: # 21 = minimal length of week_repr From ded6ee0b08abafa5f82e971a0cad80cb1f972e5d Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 7 Feb 2011 11:59:20 +0530 Subject: [PATCH 3/5] [FIX] hr_attendance:improved 'Weekly Attendance' report, prints 'h' for hours i.e.'7h06' bzr revid: mtr@mtr-20110207062920-3mudqqxvxr80d4ip --- addons/hr_attendance/report/timesheet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/hr_attendance/report/timesheet.py b/addons/hr_attendance/report/timesheet.py index 77196c4f0ae..de5bf225b4d 100644 --- a/addons/hr_attendance/report/timesheet.py +++ b/addons/hr_attendance/report/timesheet.py @@ -100,10 +100,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' %(week_wh[idx])) + week_repr.append('%s' %(str(week_wh[idx])).replace('.','h')) week_repr.append('' % num2day[idx]) week_repr.append('') - week_repr.append('%s' % sum(week_wh.values())) + week_repr.append('%s' % str(sum(week_wh.values())).replace('.','h')) week_repr.append('') week_repr.append('') if len(week_repr) > 21: # 21 = minimal length of week_repr From bcc2d840b2ff9625014fd03f5c85b78076c38ddf Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 7 Feb 2011 15:06:21 +0530 Subject: [PATCH 4/5] [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 --- .../report/attendance_by_month.py | 20 +++++++------------ addons/hr_attendance/report/timesheet.py | 13 +++--------- 2 files changed, 10 insertions(+), 23 deletions(-) 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 From e0e8422db15161b6483f42f3fb730d9a8cf4096d Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 7 Feb 2011 15:13:22 +0530 Subject: [PATCH 5/5] [IMP] hr_attendance:removed unused variable from 'Weekly Attendance' report bzr revid: mtr@mtr-20110207094322-im3nesr9lxx080vy --- addons/hr_attendance/report/timesheet.py | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/hr_attendance/report/timesheet.py b/addons/hr_attendance/report/timesheet.py index 7203b7d4f1d..7adfe98ef13 100644 --- a/addons/hr_attendance/report/timesheet.py +++ b/addons/hr_attendance/report/timesheet.py @@ -80,7 +80,6 @@ class report_custom(report_rml): attendances.append({'name': n_monday.strftime('%Y-%m-%d %H:%M:%S'), 'action': 'sign_out'}) # sum up the attendances' durations ldt = None - wh = 0.0 for att in attendances: dt = datetime.strptime(att['name'], '%Y-%m-%d %H:%M:%S') if ldt and att['action'] == 'sign_out':