-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[16.0][ADD] hr_attendance_leave_report: In Attendance Statistics Repo…
…rt new fields: Hours To Work, Leave Hours, and Worked leave hours.
- Loading branch information
1 parent
a8e8f42
commit f5f53f4
Showing
13 changed files
with
339 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
<https://github.com/avanzosc/hr-addons/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 <anajuaristi@avanzosc.es> | ||
* Alfredo de la Fuente <alfredodelafuente@avanzosc.es> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from . import report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
46 changes: 46 additions & 0 deletions
46
hr_attendance_leave_report/i18n/hr_attendance_leave_report.pot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import hr_leave |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import hr_attendance_report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
""" |
33 changes: 33 additions & 0 deletions
33
hr_attendance_leave_report/report/hr_attendance_report_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<record id="hr_attendance_report_view_pivot" model="ir.ui.view"> | ||
<field name="name">hr.attendance.report.view.pivot</field> | ||
<field name="model">hr.attendance.report</field> | ||
<field name="inherit_id" ref="hr_attendance.hr_attendance_report_view_pivot" /> | ||
<field name="arch" type="xml"> | ||
<field name="check_in" position="after"> | ||
<field name="hours_to_work" type="measure" widget="float_time" /> | ||
</field> | ||
<field name="overtime_hours" position="after"> | ||
<field name="leave_hours" type="measure" widget="float_time" /> | ||
<field name="worked_leave_hours" type="measure" widget="float_time" /> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record id="hr_attendance_report_view_graph" model="ir.ui.view"> | ||
<field name="name">hr.attendance.report.view.graph</field> | ||
<field name="model">hr.attendance.report</field> | ||
<field name="inherit_id" ref="hr_attendance.hr_attendance_report_view_graph" /> | ||
<field name="arch" type="xml"> | ||
<field name="check_in" position="after"> | ||
<field name="hours_to_work" type="measure" widget="float_time" /> | ||
</field> | ||
<field name="worked_hours" position="after"> | ||
<field name="leave_hours" type="measure" /> | ||
<field name="worked_leave_hours" type="measure" /> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |
1 change: 1 addition & 0 deletions
1
setup/hr_attendance_leave_report/odoo/addons/hr_attendance_leave_report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../hr_attendance_leave_report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |