From ba5c7fe6cca1069e0703071f7fe139ac62f5fe4e Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 2 May 2016 11:42:49 +0200 Subject: [PATCH] [ADD] hr_timesheet_attendance report Provide a timesheet/attendance report independent from hr_timesheet_sheet. --- addons/hr_timesheet_attendance/__init__.py | 3 ++ addons/hr_timesheet_attendance/__openerp__.py | 13 +++++ .../report/__init__.py | 2 + .../report/hr_timesheet_attendance_report.py | 47 ++++++++++++++++++ .../hr_timesheet_attendance_report_view.xml | 48 +++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 addons/hr_timesheet_attendance/__init__.py create mode 100644 addons/hr_timesheet_attendance/__openerp__.py create mode 100644 addons/hr_timesheet_attendance/report/__init__.py create mode 100644 addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report.py create mode 100644 addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report_view.xml diff --git a/addons/hr_timesheet_attendance/__init__.py b/addons/hr_timesheet_attendance/__init__.py new file mode 100644 index 00000000000..006edd3fd74 --- /dev/null +++ b/addons/hr_timesheet_attendance/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import report diff --git a/addons/hr_timesheet_attendance/__openerp__.py b/addons/hr_timesheet_attendance/__openerp__.py new file mode 100644 index 00000000000..e8f66a2284e --- /dev/null +++ b/addons/hr_timesheet_attendance/__openerp__.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +{ + 'name': "Timesheets/attendances reporting", + 'description': """ + """, + 'category': 'Hidden', + 'version': '0.1', + + # any module necessary for this one to work correctly + 'depends': ['hr_timesheet', 'hr_attendance'], + 'data': ['report/hr_timesheet_attendance_report_view.xml'], + 'auto_install': True, +} diff --git a/addons/hr_timesheet_attendance/report/__init__.py b/addons/hr_timesheet_attendance/report/__init__.py new file mode 100644 index 00000000000..a32b4f5eea7 --- /dev/null +++ b/addons/hr_timesheet_attendance/report/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import hr_timesheet_attendance_report diff --git a/addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report.py b/addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report.py new file mode 100644 index 00000000000..c93ea4abf1d --- /dev/null +++ b/addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- + +from openerp import api, fields, models, tools + +class TimesheetAttendance(models.Model): + _name = 'hr.timesheet.attendance.report' + _auto = False + + user_id = fields.Many2one('res.users') + date = fields.Date() + total_timesheet = fields.Float() + total_attendance = fields.Float() + total_difference = fields.Float() + + def init(self, cr): + cr.execute("""CREATE OR REPLACE VIEW %s AS ( + SELECT + max(id) AS id, + t.user_id, + t.date, + coalesce(sum(t.attendance), 0) AS total_attendance, + coalesce(sum(t.timesheet), 0) AS total_timesheet, + coalesce(sum(t.attendance), 0) - coalesce(sum(t.timesheet), 0) as total_difference + FROM ( + SELECT + -hr_attendance.id AS id, + resource_resource.user_id AS user_id, + hr_attendance.worked_hours AS attendance, + NULL AS timesheet, + date_trunc('day', hr_attendance.name) AS date + FROM hr_attendance + LEFT JOIN hr_employee ON hr_employee.id = hr_attendance.employee_id + LEFT JOIN resource_resource on resource_resource.id = hr_employee.resource_id + WHERE hr_attendance.action = 'sign_out' + UNION ALL + SELECT + ts.id AS id, + ts.user_id AS user_id, + NULL AS attendance, + ts.unit_amount AS timesheet, + date_trunc('day', ts.date) AS date + FROM account_analytic_line AS ts + ) AS t + GROUP BY t.user_id, t.date + ORDER BY t.date + ) + """ % self._table) diff --git a/addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report_view.xml b/addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report_view.xml new file mode 100644 index 00000000000..34164187167 --- /dev/null +++ b/addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report_view.xml @@ -0,0 +1,48 @@ + + + + Search for HR timesheet attendance report + hr.timesheet.attendance.report + + + + + + + + + HR timesheet attendance report: Pivot + hr.timesheet.attendance.report + + + + + + + + + + + HR Timesheet/Attendance Report + hr.timesheet.attendance.report + pivot + {'search_default_week': True} + + + + + +