diff --git a/addons/hr_attendance/__openerp__.py b/addons/hr_attendance/__openerp__.py index abdc1ad8cc1..7ff0a63a79b 100644 --- a/addons/hr_attendance/__openerp__.py +++ b/addons/hr_attendance/__openerp__.py @@ -39,8 +39,6 @@ actions(Sign in/Sign out) performed by them. 'security/ir.model.access.csv', 'hr_attendance_view.xml', 'hr_attendance_report.xml', - 'wizard/hr_attendance_bymonth_view.xml', - 'wizard/hr_attendance_byweek_view.xml', 'wizard/hr_attendance_error_view.xml', 'res_config_view.xml', 'views/report_attendanceerrors.xml', diff --git a/addons/hr_attendance/hr_attendance.py b/addons/hr_attendance/hr_attendance.py index dcff0ad5085..5495ebe4d25 100644 --- a/addons/hr_attendance/hr_attendance.py +++ b/addons/hr_attendance/hr_attendance.py @@ -20,10 +20,12 @@ ############################################################################## import time +from datetime import datetime from openerp.osv import fields, osv from openerp.tools.translate import _ + class hr_action_reason(osv.osv): _name = "hr.action.reason" _description = "Action Reason" @@ -40,14 +42,32 @@ def _employee_get(obj, cr, uid, context=None): ids = obj.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context) return ids and ids[0] or False + class hr_attendance(osv.osv): _name = "hr.attendance" _description = "Attendance" - def _day_compute(self, cr, uid, ids, fieldnames, args, context=None): - res = dict.fromkeys(ids, '') + def _worked_hours_compute(self, cr, uid, ids, fieldnames, args, context=None): + """For each hr.attendance record of action sign-in: assign 0. + For each hr.attendance record of action sign-out: assign number of hours since last sign-in. + """ + res = {} for obj in self.browse(cr, uid, ids, context=context): - res[obj.id] = time.strftime('%Y-%m-%d', time.strptime(obj.name, '%Y-%m-%d %H:%M:%S')) + if obj.action == 'sign_in': + res[obj.id] = 0 + elif obj.action == 'sign_out': + # Get the associated sign-in + last_signin_id = self.search(cr, uid, [ + ('employee_id', '=', obj.employee_id.id), + ('name', '<', obj.name), ('action', '=', 'sign_in') + ], limit=1, order='name DESC') + last_signin = self.browse(cr, uid, last_signin_id, context=context)[0] + + # Compute time elapsed between sign-in and sign-out + last_signin_datetime = datetime.strptime(last_signin.name, '%Y-%m-%d %H:%M:%S') + signout_datetime = datetime.strptime(obj.name, '%Y-%m-%d %H:%M:%S') + workedhours_datetime = (signout_datetime - last_signin_datetime) + res[obj.id] = ((workedhours_datetime.seconds) / 60) / 60 return res _columns = { @@ -55,7 +75,7 @@ class hr_attendance(osv.osv): 'action': fields.selection([('sign_in', 'Sign In'), ('sign_out', 'Sign Out'), ('action','Action')], 'Action', required=True), 'action_desc': fields.many2one("hr.action.reason", "Action Reason", domain="[('action_type', '=', action)]", help='Specifies the reason for Signing In/Signing Out in case of extra hours.'), 'employee_id': fields.many2one('hr.employee', "Employee", required=True, select=True), - 'day': fields.function(_day_compute, type='char', string='Day', store=True, select=1, size=32), + 'worked_hours': fields.function(_worked_hours_compute, type='float', string='Worked Hours', store=True), } _defaults = { 'name': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), #please don't remove the lambda, if you remove it then the current time will not change @@ -110,7 +130,7 @@ class hr_employee(osv.osv): for res in cr.fetchall(): result[res[1]] = res[0] == 'sign_in' and 'present' or 'absent' return result - + def _last_sign(self, cr, uid, ids, name, args, context=None): result = {} if not ids: diff --git a/addons/hr_attendance/hr_attendance_view.xml b/addons/hr_attendance/hr_attendance_view.xml index c38ee45b510..ae8a168a595 100644 --- a/addons/hr_attendance/hr_attendance_view.xml +++ b/addons/hr_attendance/hr_attendance_view.xml @@ -40,7 +40,6 @@ - @@ -53,17 +52,30 @@ + - + + + hr.attendance.graph + hr.attendance + + + + + + + + + Attendances hr.attendance @@ -74,12 +86,27 @@ The Time Tracking functionality aims to manage employee attendances from Sign in/Sign out actions. You can also link this feature to an attendance device using OpenERP's web service features. + + Attendance Analysis + hr.attendance + form + graph + + + + + hr.action.reason.form hr.action.reason diff --git a/addons/hr_attendance/report/__init__.py b/addons/hr_attendance/report/__init__.py index faa57ad2e95..9bb280eb645 100644 --- a/addons/hr_attendance/report/__init__.py +++ b/addons/hr_attendance/report/__init__.py @@ -20,7 +20,5 @@ ############################################################################## import attendance_errors -import attendance_by_month -import timesheet # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_attendance/report/attendance_by_month.py b/addons/hr_attendance/report/attendance_by_month.py deleted file mode 100644 index 8e8f95c81e1..00000000000 --- a/addons/hr_attendance/report/attendance_by_month.py +++ /dev/null @@ -1,196 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -from datetime import datetime, timedelta -from dateutil.relativedelta import relativedelta -import time - -import openerp -from openerp.report import report_sxw -from openerp.report.interface import report_rml -from openerp.report.interface import toxml -from openerp.tools import to_xml, ustr -from openerp.tools.translate import _ - -one_day = relativedelta(days=1) -month2name = [0, 'January', 'February', 'March', 'April', 'May', 'June', '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 lengthmonth(year, month): - if month == 2 and ((year % 4 == 0) and ((year % 100 != 0) or (year % 400 == 0))): - return 29 - return [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month] - -class report_custom(report_rml): - - def create_xml(self, cr, uid, ids, datas, context=None): - registry = openerp.registry(cr.dbname) - obj_emp = registry['hr.employee'] - if context is None: - context = {} - month = datetime(datas['form']['year'], datas['form']['month'], 1) - emp_ids = datas['active_ids'] - user_xml = ['%s' % _(month2name[month.month]), '%s' % month.year] - if emp_ids: - for emp in obj_emp.read(cr, uid, emp_ids, ['name']): - stop, days_xml = False, [] - total_wh = 0.0 - user_repr = ''' - - %s - %%s - - ''' % (ustr(toxml(emp['name']))) - today, tomor = month, month + one_day - while today.month == month.month: - #### Work hour calculation - sql = ''' - select action, att.name - from hr_employee as emp inner join hr_attendance as att - on emp.id = att.employee_id - where att.name between %s and %s and emp.id = %s - order by att.name - ''' - cr.execute(sql, (today.strftime('%Y-%m-%d %H:%M:%S'), tomor.strftime('%Y-%m-%d %H:%M:%S'), emp['id'])) - attendences = cr.dictfetchall() - wh = 0.0 - # Fake sign ins/outs at week ends, to take attendances across week ends into account - if attendences and attendences[0]['action'] == 'sign_out': - attendences.insert(0, {'name': today.strftime('%Y-%m-%d %H:%M:%S'), 'action':'sign_in'}) - if attendences and attendences[-1]['action'] == 'sign_in': - attendences.append({'name': tomor.strftime('%Y-%m-%d %H:%M:%S'), 'action':'sign_out'}) - # sum up the attendances' durations - ldt = None - for att in attendences: - dt = datetime.strptime(att['name'], '%Y-%m-%d %H:%M:%S') - if ldt and att['action'] == 'sign_out': - if dt.date() > ldt.date(): - dt = ldt - wh += (float((dt - ldt).seconds)/60/60) - else: - ldt = dt - # Week xml representation - total_wh += wh - 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 - total_wh = hour2str(total_wh) - today_xml = '%s' % (total_wh) - days_xml.append(today_xml) - user_xml.append(user_repr % '\n'.join(days_xml)) - - rpt_obj = obj_emp - rml_obj=report_sxw.rml_parse(cr, uid, rpt_obj._name,context) - header_xml = ''' -
- %s - %s -
- ''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")),to_xml(registry['res.users'].browse(cr,uid,uid).company_id.name)) - - first_date = str(month) - som = datetime.strptime(first_date, '%Y-%m-%d %H:%M:%S') - eom = som + timedelta(int(dy)-1) - day_diff=eom-som - date_xml=[] - cell=1 - date_xml.append('') - if day_diff.days>=30: - date_xml += ['' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, lengthmonth(som.year, som.month)+1)] - else: - if day_diff.days>=(lengthmonth(som.year, som.month)-som.day): - date_xml += ['' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, lengthmonth(som.year, som.month)+1)] - else: - date_xml += ['' % (x, _(som.replace(day=x).strftime('%a')),x-som.day+1) for x in range(som.day, eom.day+1)] - cell=x-som.day+1 - day_diff1=day_diff.days-cell+1 - width_dict={} - month_dict={} - i=1 - j=1 - year=som.year - month=som.month - month_dict[j]=som.strftime('%B') - width_dict[j]=cell - - while day_diff1>0: - if month+i<=12: - if day_diff1 > lengthmonth(year,i+month): # Not on 30 else you have problems when entering 01-01-2009 for example - som1=datetime.date(year,month+i,1) - date_xml += ['' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, lengthmonth(year,i+month)+1)] - i=i+1 - j=j+1 - month_dict[j]=som1.strftime('%B') - cell=cell+x - width_dict[j]=x - else: - som1=datetime.date(year,month+i,1) - date_xml += ['' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, eom.day+1)] - i=i+1 - j=j+1 - month_dict[j]=som1.strftime('%B') - cell=cell+x - width_dict[j]=x - day_diff1=day_diff1-x - else: - years=year+1 - year=years - month=0 - i=1 - if day_diff1>=30: - som1=datetime.date(years,i,1) - date_xml += ['' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, lengthmonth(years,i)+1)] - i=i+1 - j=j+1 - month_dict[j]=som1.strftime('%B') - cell=cell+x - width_dict[j]=x - else: - som1=datetime.date(years,i,1) - i=i+1 - j=j+1 - month_dict[j]=som1.strftime('%B') - date_xml += ['' % (x, _(som1.replace(day=x).strftime('%a')),cell+x) for x in range(1, eom.day+1)] - cell=cell+x - width_dict[j]=x - day_diff1=day_diff1-x - date_xml += [''] - date_xml.append('') - date_xml.append('3.5cm%s,1.2cm\n' % (',0.74cm' * (int(dy)))) - xml = ''' - - %s - %s - %s - %s - - ''' % (header_xml,_('Attendances by Month'),'\n'.join(user_xml),date_xml) - return xml - -report_custom('report.hr.attendance.bymonth', 'hr.employee', '', 'addons/hr_attendance/report/bymonth.xsl') - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_attendance/report/bymonth.xsl b/addons/hr_attendance/report/bymonth.xsl deleted file mode 100644 index 0ec0a23cc8d..00000000000 --- a/addons/hr_attendance/report/bymonth.xsl +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - week - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/addons/hr_attendance/report/hr_custom_default.xsl b/addons/hr_attendance/report/hr_custom_default.xsl deleted file mode 100644 index 2eda3a08f4b..00000000000 --- a/addons/hr_attendance/report/hr_custom_default.xsl +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - 1.3cm 19.3cm 28.5cm 19.3cm - - - - - - - - - - - - 1.3cm 19.3cm 28.5cm 19.3cm - - - - - - - - - - - diff --git a/addons/hr_attendance/report/hr_custom_rml.xsl b/addons/hr_attendance/report/hr_custom_rml.xsl deleted file mode 100644 index 64a4894613a..00000000000 --- a/addons/hr_attendance/report/hr_custom_rml.xsl +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/addons/hr_attendance/report/timesheet.py b/addons/hr_attendance/report/timesheet.py deleted file mode 100644 index 42dd686eba3..00000000000 --- a/addons/hr_attendance/report/timesheet.py +++ /dev/null @@ -1,127 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - - -from datetime import datetime -from dateutil.relativedelta import relativedelta -import time - -import openerp -from openerp import tools -from openerp.report import report_sxw -from openerp.report.interface import report_rml, toxml -from openerp.tools.translate import _ - -one_week = relativedelta(days=7) -num2day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] - -def to_hour(h): - return int(h), int(round((h - int(h)) * 60, 0)) - -class report_custom(report_rml): - - def create_xml(self, cr, uid, ids, datas, context=None): - registry = openerp.registry(cr.dbname) - obj_emp = registry['hr.employee'] - - emp_ids = datas['active_ids'] - start_date = datetime.strptime(datas['form']['init_date'], '%Y-%m-%d') - 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 - - rpt_obj = obj_emp - rml_obj=report_sxw.rml_parse(cr, uid, rpt_obj._name,context) - header_xml = ''' -
- %s - %s -
- ''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")),registry['res.users'].browse(cr,uid,uid).company_id.name) - user_xml = [] - for employee_id in emp_ids: - emp = obj_emp.read(cr, uid, [employee_id], ['id', 'name'])[0] - monday, n_monday = first_monday, first_monday + one_week - stop, week_xml = False, [] - user_repr = ''' - - %s - %%s - - ''' % tools.ustr(toxml(emp['name'])) - while monday != last_monday: - #### Work hour calculation - sql = ''' - select action, att.name - from hr_employee as emp inner join hr_attendance as att - on emp.id = att.employee_id - where att.name between %s and %s and emp.id = %s - order by att.name - ''' - for idx in range(7): - cr.execute(sql, (monday.strftime('%Y-%m-%d %H:%M:%S'), (monday + relativedelta(days=idx+1)).strftime('%Y-%m-%d %H:%M:%S'), employee_id)) - attendances = cr.dictfetchall() - week_wh = {} - # Fake sign ins/outs at week ends, to take attendances across week ends into account - # XXX this is wrong for the first sign-in ever and the last sign out to this date - if attendances and attendances[0]['action'] == 'sign_out': - attendances.insert(0, {'name': monday.strftime('%Y-%m-%d %H:%M:%S'), 'action': 'sign_in'}) - if attendances and attendances[-1]['action'] == 'sign_in': - attendances.append({'name': n_monday.strftime('%Y-%m-%d %H:%M:%S'), 'action': 'sign_out'}) - # sum up the attendances' durations - ldt = None - 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) + (float((dt - ldt).seconds)/3600) - else: - ldt = dt - - # Week xml representation - week_repr = ['', '%s' % monday.strftime('%Y-%m-%d'), '%s' % (n_monday - relativedelta(days=1)).strftime('%Y-%m-%d')] - 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('' % 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('') - week_repr.append('') - week_xml.append('\n'.join(week_repr)) - - monday, n_monday = n_monday, n_monday + one_week - user_xml.append(user_repr % '\n'.join(week_xml)) - xml = ''' - - %s - %s - %s - - ''' % (header_xml,_('Attendances by Week'),'\n'.join(user_xml)) - xml = tools.ustr(xml).encode('utf8') - return self.post_process_xml_data(cr, uid, xml, context) - -report_custom('report.hr.attendance.allweeks', 'hr.employee', '', 'addons/hr_attendance/report/timesheet.xsl') -# vim:noexpandtab:tw=0 diff --git a/addons/hr_attendance/report/timesheet.xsl b/addons/hr_attendance/report/timesheet.xsl deleted file mode 100644 index 4d113512801..00000000000 --- a/addons/hr_attendance/report/timesheet.xsl +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Employee: - - - - - - - From to - Mon - Tue - Wed - Thu - Fri - Sat - Sun - Total - - - Worked hours - - - - - - 0h00 - - - - - - - - 0h00 - - - - - - - - 0h00 - - - - - - - - 0h00 - - - - - - - - 0h00 - - - - - - - - 0h00 - - - - - - - - 0h00 - - - - - - - - - - - - - - - - - - - - diff --git a/addons/hr_attendance/test/hr_attendance_report.yml b/addons/hr_attendance/test/hr_attendance_report.yml index a5276b775d8..1a55ffcf496 100644 --- a/addons/hr_attendance/test/hr_attendance_report.yml +++ b/addons/hr_attendance/test/hr_attendance_report.yml @@ -1,11 +1,3 @@ -- - Print the HR Attendance Report By Month through the wizard -- - !python {model: hr.employee}: | - from openerp.tools import test_reports - ctx = {'model': 'hr.employee','active_ids': [ref('hr.employee_fp'),ref('hr.employee_qdp'),ref('hr.employee_al')]} - data_dict = {} - test_reports.try_report_action(cr, uid, 'action_hr_attendance_month',wiz_data=data_dict, context=ctx, our_module='hr_attendance') - Print HR Attendance Error Report through the wizard - diff --git a/addons/hr_attendance/wizard/__init__.py b/addons/hr_attendance/wizard/__init__.py index 6269c507d8c..4c7d60afa8b 100644 --- a/addons/hr_attendance/wizard/__init__.py +++ b/addons/hr_attendance/wizard/__init__.py @@ -20,7 +20,5 @@ ############################################################################## import hr_attendance_error -import hr_attendance_byweek -import hr_attendance_bymonth # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_attendance/wizard/hr_attendance_bymonth.py b/addons/hr_attendance/wizard/hr_attendance_bymonth.py deleted file mode 100644 index 93868bb2379..00000000000 --- a/addons/hr_attendance/wizard/hr_attendance_bymonth.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################### -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -import time - -from openerp.osv import osv, fields - -class hr_attendance_bymonth(osv.osv_memory): - _name = 'hr.attendance.month' - _description = 'Print Monthly Attendance Report' - _columns = { - 'month': fields.selection([(1, 'January'), (2, 'February'), (3, 'March'), (4, 'April'), (5, 'May'), (6, 'June'), (7, 'July'), (8, 'August'), (9, 'September'), (10, 'October'), (11, 'November'), (12, 'December')], 'Month', required=True), - 'year': fields.integer('Year', required=True) - } - _defaults = { - 'month': lambda *a: time.gmtime()[1], - 'year': lambda *a: time.gmtime()[0], - } - - def print_report(self, cr, uid, ids, context=None): - datas = { - 'ids': [], - 'active_ids': context['active_ids'], - 'model': 'hr.employee', - 'form': self.read(cr, uid, ids)[0] - } - return { - 'type': 'ir.actions.report.xml', - 'report_name': 'hr.attendance.bymonth', - 'datas': datas, - } - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_attendance/wizard/hr_attendance_bymonth_view.xml b/addons/hr_attendance/wizard/hr_attendance_bymonth_view.xml deleted file mode 100644 index d34a65fd05f..00000000000 --- a/addons/hr_attendance/wizard/hr_attendance_bymonth_view.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - Attendances Report Monthly - hr.attendance.month - -
- - - - -
-
-
-
-
- - - Attendances By Month - ir.actions.act_window - hr.attendance.month - form - form - new - - - - - Attendances By Month - client_print_multi - - action - hr.employee - - -
-
diff --git a/addons/hr_attendance/wizard/hr_attendance_byweek.py b/addons/hr_attendance/wizard/hr_attendance_byweek.py deleted file mode 100644 index 963a2946ffa..00000000000 --- a/addons/hr_attendance/wizard/hr_attendance_byweek.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -from datetime import datetime -from dateutil.relativedelta import relativedelta - -from openerp.osv import fields, osv - -class hr_attendance_byweek(osv.osv_memory): - _name = 'hr.attendance.week' - _description = 'Print Week Attendance Report' - _columns = { - 'init_date': fields.date('Starting Date', required=True), - 'end_date': fields.date('Ending Date', required=True) - } - _defaults = { - 'init_date': (datetime.today() - relativedelta(days=datetime.date(datetime.today()).weekday())).strftime('%Y-%m-%d'), - 'end_date': (datetime.today() + relativedelta(days=6 - datetime.date(datetime.today()).weekday())).strftime('%Y-%m-%d'), - } - - def print_report(self, cr, uid, ids, context=None): - datas = { - 'ids': [], - 'active_ids': context['active_ids'], - 'model': 'hr.employee', - 'form': self.read(cr, uid, ids)[0] - } - return { - 'type': 'ir.actions.report.xml', - 'report_name': 'hr.attendance.allweeks', - 'datas': datas, - } - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_attendance/wizard/hr_attendance_byweek_view.xml b/addons/hr_attendance/wizard/hr_attendance_byweek_view.xml deleted file mode 100644 index accbf6304c5..00000000000 --- a/addons/hr_attendance/wizard/hr_attendance_byweek_view.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - Attendances Report Weekly - hr.attendance.week - -
- - - - -
-
-
-
-
- - - Attendances By Week - ir.actions.act_window - hr.attendance.week - form - form - new - - - - - Attendances By Week - client_print_multi - - action - hr.employee - - -
-
diff --git a/addons/hr_timesheet/__init__.py b/addons/hr_timesheet/__init__.py index f29aca0a003..0ba28b1946c 100644 --- a/addons/hr_timesheet/__init__.py +++ b/addons/hr_timesheet/__init__.py @@ -21,7 +21,6 @@ import hr_timesheet import wizard -import report # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_timesheet/__openerp__.py b/addons/hr_timesheet/__openerp__.py index 6105271be77..411aac660b4 100644 --- a/addons/hr_timesheet/__openerp__.py +++ b/addons/hr_timesheet/__openerp__.py @@ -46,8 +46,6 @@ up a management by affair. 'security/ir.model.access.csv', 'security/hr_timesheet_security.xml', 'hr_timesheet_view.xml', - 'hr_timesheet_report.xml', - 'hr_timesheet_wizard.xml', 'process/hr_timesheet_process.xml', 'wizard/hr_timesheet_sign_in_out_view.xml', 'hr_timesheet_installer.xml', diff --git a/addons/hr_timesheet/hr_timesheet_report.xml b/addons/hr_timesheet/hr_timesheet_report.xml deleted file mode 100644 index 487dcd592bd..00000000000 --- a/addons/hr_timesheet/hr_timesheet_report.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/addons/hr_timesheet/hr_timesheet_wizard.xml b/addons/hr_timesheet/hr_timesheet_wizard.xml deleted file mode 100644 index ebc084668b7..00000000000 --- a/addons/hr_timesheet/hr_timesheet_wizard.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/addons/hr_timesheet/report/__init__.py b/addons/hr_timesheet/report/__init__.py deleted file mode 100644 index 8304c90421d..00000000000 --- a/addons/hr_timesheet/report/__init__.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -import user_timesheet -import users_timesheet - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_timesheet/report/custom_default.xsl b/addons/hr_timesheet/report/custom_default.xsl deleted file mode 100644 index 2eda3a08f4b..00000000000 --- a/addons/hr_timesheet/report/custom_default.xsl +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - 1.3cm 19.3cm 28.5cm 19.3cm - - - - - - - - - - - - 1.3cm 19.3cm 28.5cm 19.3cm - - - - - - - - - - - diff --git a/addons/hr_timesheet/report/custom_rml.xsl b/addons/hr_timesheet/report/custom_rml.xsl deleted file mode 100644 index 64a4894613a..00000000000 --- a/addons/hr_timesheet/report/custom_rml.xsl +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/addons/hr_timesheet/report/user_timesheet.py b/addons/hr_timesheet/report/user_timesheet.py deleted file mode 100644 index 63edf3cc398..00000000000 --- a/addons/hr_timesheet/report/user_timesheet.py +++ /dev/null @@ -1,124 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -import datetime -import time - -import openerp -from openerp.report.interface import report_rml -from openerp.report.interface import toxml -from openerp.tools.translate import _ -from openerp.report import report_sxw -from openerp.tools import ustr -from openerp.tools import to_xml - -def lengthmonth(year, month): - if month == 2 and ((year % 4 == 0) and ((year % 100 != 0) or (year % 400 == 0))): - return 29 - return [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month] - -class report_custom(report_rml): - - def get_month_name(self, cr, uid, month, context=None): - _months = {1:_("January"), 2:_("February"), 3:_("March"), 4:_("April"), 5:_("May"), 6:_("June"), 7:_("July"), 8:_("August"), 9:_("September"), 10:_("October"), 11:_("November"), 12:_("December")} - return _months[month] - def get_weekday_name(self, cr, uid, weekday, context=None): - _weekdays = {1:_('Mon'), 2:_('Tue'), 3:_('Wed'), 4:_('Thu'), 5:_('Fri'), 6:_('Sat'), 7:_('Sun')} - return _weekdays[weekday] - - def create_xml(self, cr, uid, ids, data, context): - registry = openerp.registry(cr.dbname) - - # Get the user id from the selected employee record - emp_id = data['form']['employee_id'] - emp_obj = registry['hr.employee'] - user_id = emp_obj.browse(cr, uid, emp_id).user_id.id - empl_name = emp_obj.browse(cr, uid, emp_id).name - - # Computing the dates (start of month: som, and end of month: eom) - som = datetime.date(data['form']['year'], data['form']['month'], 1) - eom = som + datetime.timedelta(lengthmonth(som.year, som.month)) - - date_xml = ['' % (self.get_month_name(cr, uid, som.month, context=context), som.year), ''] - date_xml += ['' % (x, self.get_weekday_name(cr, uid, som.replace(day=x).weekday()+1, context=context), som.replace(day=x).weekday()+1) for x in range(1, lengthmonth(som.year, som.month)+1)] - - date_xml.append('') - date_xml.append('2.5cm%s,2cm\n' % (',0.7cm' * lengthmonth(som.year, som.month))) - - # Sum attendence by account, then by day - accounts = {} - header_xml = '' - if user_id: - # Computing the attendence by analytical account - cr.execute( - "select line.date, (unit_amount / unit.factor) as amount, account_id, account.name "\ - "from account_analytic_line as line, hr_analytic_timesheet as hr, "\ - "account_analytic_account as account, product_uom as unit "\ - "where hr.line_id=line.id and line.account_id=account.id "\ - "and product_uom_id = unit.id "\ - "and line.user_id=%s and line.date >= %s and line.date < %s " - "order by line.date", - (user_id, som.strftime('%Y-%m-%d'), eom.strftime('%Y-%m-%d'))) - - for presence in cr.dictfetchall(): - day = int(presence['date'][-2:]) - account = accounts.setdefault((presence['account_id'], presence['name']), {}) - account[day] = account.get(day, 0.0) + presence['amount'] - - xml = ''' - - %.2f - - ''' - rpt_obj = registry['hr.employee'] - rml_obj = report_sxw.rml_parse(cr, uid, rpt_obj._name,context) - if user_id: - header_xml = ''' -
- %s - %s -
- ''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")),to_xml(registry['res.users'].browse(cr,uid,user_id).company_id.name)) - - account_xml = [] - for account, telems in accounts.iteritems(): - aid, aname = account - aname = registry['account.analytic.account'].name_get(cr, uid, [aid], context) - aname = aname[0][1] - - account_xml.append('' % (aid, toxml(aname))) - account_xml.append('\n'.join([xml % (day, amount) for day, amount in telems.iteritems()])) - account_xml.append('') - - # Computing the xml - xml = ''' - - %s - %s - %s - - ''' % (header_xml, ustr(toxml(empl_name)), '\n'.join(date_xml) + '\n'.join(account_xml)) - return xml - -report_custom('report.hr.analytical.timesheet', 'hr.employee', '', 'addons/hr_timesheet/report/user_timesheet.xsl') - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_timesheet/report/user_timesheet.xsl b/addons/hr_timesheet/report/user_timesheet.xsl deleted file mode 100644 index b58e8af33b2..00000000000 --- a/addons/hr_timesheet/report/user_timesheet.xsl +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - lightgrey - - - ,0 - - - - ,-1 - - - - - - - - - - - - - - Timesheet by Employee - - - - - month - - - - - - - - - - - - - - - - - - Total - - - - Sum - - - - - - - glande - - - normal_people - - - esclave - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/addons/hr_timesheet/report/users_timesheet.py b/addons/hr_timesheet/report/users_timesheet.py deleted file mode 100644 index 0d3f23e6bd3..00000000000 --- a/addons/hr_timesheet/report/users_timesheet.py +++ /dev/null @@ -1,123 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -import datetime -import time - -import openerp -from openerp.report.interface import report_rml -from openerp.report.interface import toxml -from openerp.tools.translate import _ -from openerp.report import report_sxw -from openerp.tools import ustr - - -def lengthmonth(year, month): - if month == 2 and ((year % 4 == 0) and ((year % 100 != 0) or (year % 400 == 0))): - return 29 - return [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month] - -def emp_create_xml(cr, id, som, eom, emp): - # Computing the attendence by analytical account - cr.execute( - "select line.date, (unit_amount / unit.factor) as amount "\ - "from account_analytic_line as line, hr_analytic_timesheet as hr, "\ - "product_uom as unit "\ - "where hr.line_id=line.id "\ - "and product_uom_id = unit.id "\ - "and line.user_id=%s and line.date >= %s and line.date < %s " - "order by line.date", - (id, som.strftime('%Y-%m-%d'), eom.strftime('%Y-%m-%d'))) - - # Sum by day - month = {} - for presence in cr.dictfetchall(): - day = int(presence['date'][-2:]) - month[day] = month.get(day, 0.0) + presence['amount'] - - xml = ''' - - %.2f - - ''' - time_xml = ([xml % (day, amount) for day, amount in month.iteritems()]) - - # Computing the xml - xml = ''' - - %s - - ''' % (id, toxml(emp), '\n'.join(time_xml)) - return xml - -class report_custom(report_rml): - - def get_month_name(self, cr, uid, month, context=None): - _months = {1:_("January"), 2:_("February"), 3:_("March"), 4:_("April"), 5:_("May"), 6:_("June"), 7:_("July"), 8:_("August"), 9:_("September"), 10:_("October"), 11:_("November"), 12:_("December")} - return _months[month] - - def get_weekday_name(self, cr, uid, weekday, context=None): - _weekdays = {1:_('Mon'), 2:_('Tue'), 3:_('Wed'), 4:_('Thu'), 5:_('Fri'), 6:_('Sat'), 7:_('Sun')} - return _weekdays[weekday] - - def create_xml(self, cr, uid, ids, data, context): - registry = openerp.registry(cr.dbname) - - # Computing the dates (start of month: som, and end of month: eom) - som = datetime.date(data['form']['year'], data['form']['month'], 1) - eom = som + datetime.timedelta(lengthmonth(som.year, som.month)) - date_xml = ['' % (self.get_month_name(cr, uid, som.month, context=context), som.year), ''] - date_xml += ['' % (x, self.get_weekday_name(cr, uid, som.replace(day=x).weekday()+1, context=context), som.replace(day=x).weekday()+1) for x in range(1, lengthmonth(som.year, som.month)+1)] - date_xml.append('') - date_xml.append('2.5cm%s,2cm\n' % (',0.7cm' * lengthmonth(som.year, som.month))) - - emp_xml='' - emp_obj = registry['hr.employee'] - for id in data['form']['employee_ids']: - user = emp_obj.browse(cr, uid, id).user_id.id - empl_name = emp_obj.browse(cr, uid, id).name - if user: - emp_xml += emp_create_xml(cr, user, som, eom, empl_name) - # Computing the xml - #Without this, report don't show non-ascii characters (TO CHECK) - date_xml = '\n'.join(date_xml) - rpt_obj = emp_obj - rml_obj=report_sxw.rml_parse(cr, uid, rpt_obj._name,context) - header_xml = ''' -
- %s - %s -
- ''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")),toxml(registry['res.users'].browse(cr,uid,uid).company_id.name)) - - xml=''' - - %s - %s - %s - - ''' % (header_xml,date_xml, ustr(emp_xml)) - return xml - -report_custom('report.hr.analytical.timesheet_users', 'hr.employee', '', 'addons/hr_timesheet/report/users_timesheet.xsl') - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/addons/hr_timesheet/report/users_timesheet.xsl b/addons/hr_timesheet/report/users_timesheet.xsl deleted file mode 100644 index 9c99b56afe6..00000000000 --- a/addons/hr_timesheet/report/users_timesheet.xsl +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - lightgrey - - - ,0 - - - - ,-1 - - - - - - - - - - - - - - Employees Timesheet - - - month - - - - - - - - - - - - - - - - - - Total - - - - - - - - - - - - - glande - - - normal_people - - - esclave - - - - - - - - - - - - - Total - - - - - - - - -