diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/hr_timesheet_attendance/report | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/hr_timesheet_attendance/report')
3 files changed, 101 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <data> + <record id="view_hr_timesheet_attendance_report_search" model="ir.ui.view"> + <field name="name">Search for HR timesheet attendance report</field> + <field name="model">hr.timesheet.attendance.report</field> + <field name="arch" type="xml"> + <search string="timesheet attendance"> + <field name="user_id"/> + <filter name="month" string="Date" date="date"/> + <filter name="group_by_month" string="Date" date="date" context="{'group_by': 'date'}"/> + </search> + </field> + </record> + <record id="view_hr_timesheet_attendance_report_pivot" model="ir.ui.view"> + <field name="name">HR timesheet attendance report: Pivot</field> + <field name="model">hr.timesheet.attendance.report</field> + <field name="arch" type="xml"> + <pivot string="timesheet attendance" disable_linking="True" sample="1"> + <field name="date" interval="month" type="row"/> + <field name="total_attendance" type="measure" widget="timesheet_uom"/> + <field name="total_timesheet" type="measure" widget="timesheet_uom"/> + <field name="total_difference" type="measure" widget="timesheet_uom"/> + </pivot> + </field> + </record> + + <record id="action_hr_timesheet_attendance_report" model="ir.actions.act_window"> + <field name="name">Timesheet / Attendance</field> + <field name="res_model">hr.timesheet.attendance.report</field> + <field name="view_mode">graph,pivot</field> + <field name="view_id" ref="view_hr_timesheet_attendance_report_pivot"/> + <field name="context">{'search_default_group_by_month': True}</field> + <field name="help" type="html"> + <p class="o_view_nocontent_smiling_face"> + No data yet! + </p> + </field> + </record> + + <menuitem id="menu_hr_timesheet_attendance_report" + parent="hr_timesheet.menu_timesheets_reports" + action="action_hr_timesheet_attendance_report" + name="Timesheet / Attendance"/> + </data> +</odoo> |
