From f5f53f46a86976755d1be5d424cb62acf12ab940 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 19 Sep 2024 07:34:01 +0200 Subject: [PATCH] [16.0][ADD] hr_attendance_leave_report: In Attendance Statistics Report new fields: Hours To Work, Leave Hours, and Worked leave hours. --- hr_attendance_leave_report/README.rst | 29 +++++++ hr_attendance_leave_report/__init__.py | 2 + hr_attendance_leave_report/__manifest__.py | 18 ++++ hr_attendance_leave_report/i18n/en_GB.po | 46 ++++++++++ hr_attendance_leave_report/i18n/es.po | 46 ++++++++++ .../i18n/hr_attendance_leave_report.pot | 46 ++++++++++ hr_attendance_leave_report/models/__init__.py | 1 + hr_attendance_leave_report/models/hr_leave.py | 23 +++++ hr_attendance_leave_report/report/__init__.py | 1 + .../report/hr_attendance_report.py | 87 +++++++++++++++++++ .../report/hr_attendance_report_views.xml | 33 +++++++ .../odoo/addons/hr_attendance_leave_report | 1 + setup/hr_attendance_leave_report/setup.py | 6 ++ 13 files changed, 339 insertions(+) create mode 100644 hr_attendance_leave_report/README.rst create mode 100644 hr_attendance_leave_report/__init__.py create mode 100644 hr_attendance_leave_report/__manifest__.py create mode 100644 hr_attendance_leave_report/i18n/en_GB.po create mode 100644 hr_attendance_leave_report/i18n/es.po create mode 100644 hr_attendance_leave_report/i18n/hr_attendance_leave_report.pot create mode 100644 hr_attendance_leave_report/models/__init__.py create mode 100644 hr_attendance_leave_report/models/hr_leave.py create mode 100644 hr_attendance_leave_report/report/__init__.py create mode 100644 hr_attendance_leave_report/report/hr_attendance_report.py create mode 100644 hr_attendance_leave_report/report/hr_attendance_report_views.xml create mode 120000 setup/hr_attendance_leave_report/odoo/addons/hr_attendance_leave_report create mode 100644 setup/hr_attendance_leave_report/setup.py diff --git a/hr_attendance_leave_report/README.rst b/hr_attendance_leave_report/README.rst new file mode 100644 index 0000000..8bd222b --- /dev/null +++ b/hr_attendance_leave_report/README.rst @@ -0,0 +1,29 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +========================== +Hr attendance leave report +========================== + +* In Attendance Statistics Report new fields: Hours To Work, Leave Hours, + and Worked leave hours. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, +please check there if your issue has already been reported. If you spotted +it first, help us smash it by providing detailed and welcomed feedback. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Contributors +------------ + +* Ana Juaristi +* Alfredo de la Fuente diff --git a/hr_attendance_leave_report/__init__.py b/hr_attendance_leave_report/__init__.py new file mode 100644 index 0000000..bf588bc --- /dev/null +++ b/hr_attendance_leave_report/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import report diff --git a/hr_attendance_leave_report/__manifest__.py b/hr_attendance_leave_report/__manifest__.py new file mode 100644 index 0000000..b0a05fe --- /dev/null +++ b/hr_attendance_leave_report/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2024 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Hr Attendance Leave Report", + "version": "16.0.1.0.0", + "category": "Human Resources/Attendances", + "license": "AGPL-3", + "author": "AvanzOSC", + "website": "https://github.com/avanzosc/hr-addons", + "depends": [ + "hr_attendance", + ], + "excludes": [], + "data": [ + "report/hr_attendance_report_views.xml", + ], + "installable": True, +} diff --git a/hr_attendance_leave_report/i18n/en_GB.po b/hr_attendance_leave_report/i18n/en_GB.po new file mode 100644 index 0000000..2a73af0 --- /dev/null +++ b/hr_attendance_leave_report/i18n/en_GB.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_attendance_leave_report +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-09-19 05:18+0000\n" +"PO-Revision-Date: 2024-09-19 05:18+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: hr_attendance_leave_report +#: model:ir.model,name:hr_attendance_leave_report.model_hr_attendance_report +msgid "Attendance Statistics" +msgstr "" + +#. module: hr_attendance_leave_report +#: model:ir.model.fields,field_description:hr_attendance_leave_report.field_hr_attendance_report__hours_to_work +msgid "Hours To Work" +msgstr "" + +#. module: hr_attendance_leave_report +#: model:ir.model.fields,field_description:hr_attendance_leave_report.field_hr_leave__hours_duration +msgid "Hours durations" +msgstr "" + +#. module: hr_attendance_leave_report +#: model:ir.model.fields,field_description:hr_attendance_leave_report.field_hr_attendance_report__leave_hours +msgid "Leave Hours" +msgstr "" + +#. module: hr_attendance_leave_report +#: model:ir.model,name:hr_attendance_leave_report.model_hr_leave +msgid "Time Off" +msgstr "" + +#. module: hr_attendance_leave_report +#: model:ir.model.fields,field_description:hr_attendance_leave_report.field_hr_attendance_report__worked_leave_hours +msgid "Worked leave hours" +msgstr "" diff --git a/hr_attendance_leave_report/i18n/es.po b/hr_attendance_leave_report/i18n/es.po new file mode 100644 index 0000000..dc58aa5 --- /dev/null +++ b/hr_attendance_leave_report/i18n/es.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_attendance_leave_report +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-09-19 05:18+0000\n" +"PO-Revision-Date: 2024-09-19 05:18+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: hr_attendance_leave_report +#: model:ir.model,name:hr_attendance_leave_report.model_hr_attendance_report +msgid "Attendance Statistics" +msgstr "Estadísticas de asistencia" + +#. module: hr_attendance_leave_report +#: model:ir.model.fields,field_description:hr_attendance_leave_report.field_hr_attendance_report__hours_to_work +msgid "Hours To Work" +msgstr "Horas a trabajar" + +#. module: hr_attendance_leave_report +#: model:ir.model.fields,field_description:hr_attendance_leave_report.field_hr_leave__hours_duration +msgid "Hours durations" +msgstr "Duraciones horas" + +#. module: hr_attendance_leave_report +#: model:ir.model.fields,field_description:hr_attendance_leave_report.field_hr_attendance_report__leave_hours +msgid "Leave Hours" +msgstr "Horas Ausencia" + +#. module: hr_attendance_leave_report +#: model:ir.model,name:hr_attendance_leave_report.model_hr_leave +msgid "Time Off" +msgstr "Ausencias" + +#. module: hr_attendance_leave_report +#: model:ir.model.fields,field_description:hr_attendance_leave_report.field_hr_attendance_report__worked_leave_hours +msgid "Worked leave hours" +msgstr "Horas ausencia trabajadas" diff --git a/hr_attendance_leave_report/i18n/hr_attendance_leave_report.pot b/hr_attendance_leave_report/i18n/hr_attendance_leave_report.pot new file mode 100644 index 0000000..2a73af0 --- /dev/null +++ b/hr_attendance_leave_report/i18n/hr_attendance_leave_report.pot @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_attendance_leave_report +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-09-19 05:18+0000\n" +"PO-Revision-Date: 2024-09-19 05:18+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: hr_attendance_leave_report +#: model:ir.model,name:hr_attendance_leave_report.model_hr_attendance_report +msgid "Attendance Statistics" +msgstr "" + +#. module: hr_attendance_leave_report +#: model:ir.model.fields,field_description:hr_attendance_leave_report.field_hr_attendance_report__hours_to_work +msgid "Hours To Work" +msgstr "" + +#. module: hr_attendance_leave_report +#: model:ir.model.fields,field_description:hr_attendance_leave_report.field_hr_leave__hours_duration +msgid "Hours durations" +msgstr "" + +#. module: hr_attendance_leave_report +#: model:ir.model.fields,field_description:hr_attendance_leave_report.field_hr_attendance_report__leave_hours +msgid "Leave Hours" +msgstr "" + +#. module: hr_attendance_leave_report +#: model:ir.model,name:hr_attendance_leave_report.model_hr_leave +msgid "Time Off" +msgstr "" + +#. module: hr_attendance_leave_report +#: model:ir.model.fields,field_description:hr_attendance_leave_report.field_hr_attendance_report__worked_leave_hours +msgid "Worked leave hours" +msgstr "" diff --git a/hr_attendance_leave_report/models/__init__.py b/hr_attendance_leave_report/models/__init__.py new file mode 100644 index 0000000..e68e996 --- /dev/null +++ b/hr_attendance_leave_report/models/__init__.py @@ -0,0 +1 @@ +from . import hr_leave diff --git a/hr_attendance_leave_report/models/hr_leave.py b/hr_attendance_leave_report/models/hr_leave.py new file mode 100644 index 0000000..eabe541 --- /dev/null +++ b/hr_attendance_leave_report/models/hr_leave.py @@ -0,0 +1,23 @@ +# Copyright 2024 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, fields, models +from odoo.tools import float_round + + +class HrLeave(models.Model): + _inherit = "hr.leave" + + hours_duration = fields.Float( + string="Hours durations", + store=True, + copy=False, + compute="_compute_hours_duration", + ) + + @api.depends("number_of_hours_display", "number_of_days_display") + def _compute_hours_duration(self): + for leave in self: + hours = 0 + if leave.leave_type_request_unit == "hour": + hours = float_round(leave.number_of_hours_display, precision_digits=2) + leave.hours_duration = hours diff --git a/hr_attendance_leave_report/report/__init__.py b/hr_attendance_leave_report/report/__init__.py new file mode 100644 index 0000000..adbf4aa --- /dev/null +++ b/hr_attendance_leave_report/report/__init__.py @@ -0,0 +1 @@ +from . import hr_attendance_report diff --git a/hr_attendance_leave_report/report/hr_attendance_report.py b/hr_attendance_leave_report/report/hr_attendance_report.py new file mode 100644 index 0000000..335e189 --- /dev/null +++ b/hr_attendance_leave_report/report/hr_attendance_report.py @@ -0,0 +1,87 @@ +# Copyright 2024 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, fields, models, tools + + +class HRAttendanceReport(models.Model): + _inherit = "hr.attendance.report" + + hours_to_work = fields.Float(readonly=True) + leave_hours = fields.Float(readonly=True) + worked_leave_hours = fields.Float(string="Worked leave hours", readonly=True) + + @api.model + def _select(self): + select = super()._select() + my_select = """ + (select sum(cal.hour_to - cal.hour_from) + from resource_calendar_attendance cal, + resource_calendar reso, + hr_employee emp + where reso.id = cal.calendar_id + and emp.id = hra.employee_id + and emp.resource_calendar_id = reso.id + and ( + (to_char(hra.check_in,'d') = '1' and cal.dayofweek = '6') or + (to_char(hra.check_in,'d') = '2' and cal.dayofweek = '0') or + (to_char(hra.check_in,'d') = '3' and cal.dayofweek = '1') or + (to_char(hra.check_in,'d') = '4' and cal.dayofweek = '2') or + (to_char(hra.check_in,'d') = '5' and cal.dayofweek = '3') or + (to_char(hra.check_in,'d') = '6' and cal.dayofweek = '4') or + (to_char(hra.check_in,'d') = '7' and cal.dayofweek = '5') + ) + ) as hours_to_work, 0 as leave_hours, 0 as worked_leave_hours + """ + new_select = "{}, {}".format(select, my_select) + return new_select + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute( + """ + CREATE OR REPLACE VIEW %s AS ( + %s + %s + %s + %s + ) + """ + % (self._table, self._select(), self._from(), self._join(), self._union()) + ) + + @api.model + def _union(self): + return """ + UNION SELECT + cast(cast(hrl.id as varchar) || cast(hrl.employee_id as varchar) || + EXTRACT(DAY FROM generate_series(request_date_from, + request_date_to, '1 day')) as integer) * -1 as id, + hrl.department_id, + hrl.employee_id, + hrl.employee_company_id, + generate_series(request_date_from, request_date_to, '1 day') as check_in, + 0 as worked_hours, + 0 as overtime_hours, + 0 as hours_to_work, + (select (l.hours_duration / (1 + l.request_date_to - l.request_date_from)) + from hr_leave l + where l.id = hrl.id + and l.holiday_status_id = ( + select hr_leave_type.id + from hr_leave_type + where hr_leave_type.id = l.holiday_status_id + and hr_leave_type.time_type = 'leave') + ) as leave_hours, + (select (l.hours_duration / (1 + l.request_date_to - l.request_date_from)) + from hr_leave l + where l.id = hrl.id + and l.holiday_status_id = ( + select hr_leave_type.id + from hr_leave_type + where hr_leave_type.id = l.holiday_status_id + and hr_leave_type.time_type = 'other') + ) as worked_leave_hours + + FROM hr_leave as hrl + WHERE hrl.state = 'validate' + """ diff --git a/hr_attendance_leave_report/report/hr_attendance_report_views.xml b/hr_attendance_leave_report/report/hr_attendance_report_views.xml new file mode 100644 index 0000000..0856b0e --- /dev/null +++ b/hr_attendance_leave_report/report/hr_attendance_report_views.xml @@ -0,0 +1,33 @@ + + + + + hr.attendance.report.view.pivot + hr.attendance.report + + + + + + + + + + + + + + hr.attendance.report.view.graph + hr.attendance.report + + + + + + + + + + + + diff --git a/setup/hr_attendance_leave_report/odoo/addons/hr_attendance_leave_report b/setup/hr_attendance_leave_report/odoo/addons/hr_attendance_leave_report new file mode 120000 index 0000000..d313e80 --- /dev/null +++ b/setup/hr_attendance_leave_report/odoo/addons/hr_attendance_leave_report @@ -0,0 +1 @@ +../../../../hr_attendance_leave_report \ No newline at end of file diff --git a/setup/hr_attendance_leave_report/setup.py b/setup/hr_attendance_leave_report/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/hr_attendance_leave_report/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)