From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/hr_timesheet_attendance/report/__init__.py | 4 ++ .../report/hr_timesheet_attendance_report.py | 51 ++++++++++++++++++++++ .../report/hr_timesheet_attendance_report_view.xml | 46 +++++++++++++++++++ 3 files changed, 101 insertions(+) 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 (limited to 'addons/hr_timesheet_attendance/report') diff --git a/addons/hr_timesheet_attendance/report/__init__.py b/addons/hr_timesheet_attendance/report/__init__.py new file mode 100644 index 00000000..bfe5a138 --- /dev/null +++ b/addons/hr_timesheet_attendance/report/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +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 00000000..94c06f58 --- /dev/null +++ b/addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models, tools + + +class TimesheetAttendance(models.Model): + _name = 'hr.timesheet.attendance.report' + _auto = False + _description = 'Timesheet Attendance Report' + + user_id = fields.Many2one('res.users') + date = fields.Date() + total_timesheet = fields.Float() + total_attendance = fields.Float() + total_difference = fields.Float() + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self._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, + hr_attendance.check_in::date 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 + UNION ALL + SELECT + ts.id AS id, + ts.user_id AS user_id, + NULL AS attendance, + ts.unit_amount AS timesheet, + ts.date AS date + FROM account_analytic_line AS ts + WHERE ts.project_id IS NOT NULL + ) 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 00000000..9c7cad68 --- /dev/null +++ b/addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report_view.xml @@ -0,0 +1,46 @@ + + + + + Search for HR timesheet attendance report + hr.timesheet.attendance.report + + + + + + + + + + HR timesheet attendance report: Pivot + hr.timesheet.attendance.report + + + + + + + + + + + + Timesheet / Attendance + hr.timesheet.attendance.report + graph,pivot + + {'search_default_group_by_month': True} + +

+ No data yet! +

+
+
+ + +
+
-- cgit v1.2.3