Skip to content

Commit

Permalink
[15.0][ADD] hr_attendance_overview
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneMangin committed Dec 10, 2024
1 parent f380a81 commit faa69c2
Show file tree
Hide file tree
Showing 22 changed files with 611 additions and 0 deletions.
137 changes: 137 additions & 0 deletions hr_attendance_overview/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
======================
HR Attendance Overview
======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:56907b4dc0640ced58028f1a9b05c9270e4569231a78c5c24c31eca6b1c6f6dc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr--attendance-lightgray.png?logo=github
:target: https://github.com/OCA/hr-attendance/tree/15.0/hr_attendance_overview
:alt: OCA/hr-attendance
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-attendance-15-0/hr-attendance-15-0-hr_attendance_overview
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/hr-attendance&target_branch=15.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds a dashboard to manage attendances and contractual hours.

General overview
================

Main purpose of this dashboard is to allow employee and manager to have an overview of their attendances according to their contract.

Two dashboards will be needed to have two axes of analysis and will cover the attendance and the contractual time of the employee.

Detailed requirements
=====================

Dashboard Attendances report
----------------------------

Attendance report will allow to calculate the undertime or overtime of the employee at a day level. For this purpose we need to calculate the contractual hours the employee is requested to do for each day. Sum of the contractual hours, leaves and attendances will give the time variation according to the contract.

Contractual hours should be calculated taking in account the following requirements:

- Calculation per day should take in account the contract valid at the date (for the future if there is no end date for the contract we use the current one)
- Working time per day will use the work plan (resource calendar) on the employee contract with the data per day and if not available the average per day (only the working days)
- Bank holiday should be excluded and they can come from the the calendar or the OCA module Public holiday (if installed)
- Number will be show in negative (in order that the final sum is negative if there is insufficient attendances according to the contract time

Attendance section have the following requirement

- Working time and time off should be clearly separated (two columns)
- Time off are taken only if fully validated
- By default we filter the current year until today and the user data.

Global requirement
------------------
Data coming from the attendances should always represent the situation we get if we go to the attendances app (data should be in real time). We accept that the data linked to the contract are updated every 24 hours.

At the initialisation the system should be able to generate the past data.

Security
--------

Employee should not see data from other employees.
One exception for a manager that can see all the data from employees he is the manager of.

Pitfalls
========

- Limit cases about hours on weekend and hours worked at night inbetween 2 days.

**Table of contents**

.. contents::
:local:

Usage
=====

To generate employee hours lines at first install:

# Go to *HR Report Dashboard* > *Update HR Employee hours*

Then select the employees and the period you want to generate the lines for.
You also select only certain hour types:

- Contractual
- Timesheet
- Attendance


Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr-attendance/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/hr-attendance/issues/new?body=module:%20hr_attendance_overview%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Camptocamp SA

Contributors
~~~~~~~~~~~~

* Florent Xicluna <[email protected]>
* Stéphane Mangin <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/hr-attendance <https://github.com/OCA/hr-attendance/tree/15.0/hr_attendance_overview>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions hr_attendance_overview/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import models
from . import report
from . import wizards
18 changes: 18 additions & 0 deletions hr_attendance_overview/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "HR Attendance Overview",
"version": "15.0.1.0.0",
"author": "Camptocamp SA",
"license": "AGPL-3",
"category": "Human Resources",
"depends": ["hr_timesheet_overview", "hr_attendance"],
"website": "https://github.com/OCA/hr-attendance",
"data": [
"security/ir.model.access.csv",
"wizards/hr_employee_hour_updater_view.xml",
"report/hr_employee_attendance_report_views.xml",
],
"installable": True,
}
2 changes: 2 additions & 0 deletions hr_attendance_overview/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import hr_attendance
from . import hr_employee_hour
34 changes: 34 additions & 0 deletions hr_attendance_overview/models/hr_attendance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class HrAttendance(models.Model):
_name = "hr.attendance"
_inherit = ["hr.attendance", "hr.employee.hour.mixin"]

def prepare_hr_employee_hour_values(self, **kwargs):
model_id = self._get_model_id()
values_list = []
cached_by_date = self.env.context.get("attendances_by_date")
for attendance in self:
check_in_date = attendance.check_in.date()
contract_hours, contract_day = self._contract_hours_day(
attendance.employee_id,
check_in_date,
cache=cached_by_date,
)
values = {
"model_id": model_id,
"res_id": attendance.id,
"type": "attendance",
"date": check_in_date,
"employee_id": attendance.employee_id.id,
"hours_qty": attendance.worked_hours,
"days_qty": attendance.worked_hours / contract_hours,
"check_in": attendance.check_in,
"check_out": attendance.check_out,
}
values_list.append(values)
return values_list
19 changes: 19 additions & 0 deletions hr_attendance_overview/models/hr_employee_hour.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, fields, models

TYPE_SELECTION = [
("attendance", _("Check-In")),
]
ONDELETE_SELECTION = {
"attendance": "set default",
}


class HrEmployeeHour(models.Model):
_inherit = "hr.employee.hour"

type = fields.Selection(selection_add=TYPE_SELECTION, ondelete=ONDELETE_SELECTION)
check_in = fields.Datetime()
check_out = fields.Datetime()
2 changes: 2 additions & 0 deletions hr_attendance_overview/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Florent Xicluna <[email protected]>
* Stéphane Mangin <[email protected]>
46 changes: 46 additions & 0 deletions hr_attendance_overview/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
This module adds a dashboard to manage attendances and contractual hours.

General overview
================

Main purpose of this dashboard is to allow employee and manager to have an overview of their attendances according to their contract.

Two dashboards will be needed to have two axes of analysis and will cover the attendance and the contractual time of the employee.

Detailed requirements
=====================

Dashboard Attendances report
----------------------------

Attendance report will allow to calculate the undertime or overtime of the employee at a day level. For this purpose we need to calculate the contractual hours the employee is requested to do for each day. Sum of the contractual hours, leaves and attendances will give the time variation according to the contract.

Contractual hours should be calculated taking in account the following requirements:

- Calculation per day should take in account the contract valid at the date (for the future if there is no end date for the contract we use the current one)
- Working time per day will use the work plan (resource calendar) on the employee contract with the data per day and if not available the average per day (only the working days)
- Bank holiday should be excluded and they can come from the the calendar or the OCA module Public holiday (if installed)
- Number will be show in negative (in order that the final sum is negative if there is insufficient attendances according to the contract time

Attendance section have the following requirement

- Working time and time off should be clearly separated (two columns)
- Time off are taken only if fully validated
- By default we filter the current year until today and the user data.

Global requirement
------------------
Data coming from the attendances should always represent the situation we get if we go to the attendances app (data should be in real time). We accept that the data linked to the contract are updated every 24 hours.

At the initialisation the system should be able to generate the past data.

Security
--------

Employee should not see data from other employees.
One exception for a manager that can see all the data from employees he is the manager of.

Pitfalls
========

- Limit cases about hours on weekend and hours worked at night inbetween 2 days.
11 changes: 11 additions & 0 deletions hr_attendance_overview/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
To generate employee hours lines at first install:

# Go to *HR Report Dashboard* > *Update HR Employee hours*

Then select the employees and the period you want to generate the lines for.
You also select only certain hour types:

- Contractual
- Timesheet
- Attendance

2 changes: 2 additions & 0 deletions hr_attendance_overview/report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import hr_employee_attendance_report
from . import hr_employee_hour_report
33 changes: 33 additions & 0 deletions hr_attendance_overview/report/hr_employee_attendance_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models

from ..models.hr_employee_hour import ONDELETE_SELECTION, TYPE_SELECTION


class HrEmployeeAttendanceReport(models.Model):
_name = "hr.employee.attendance.report"
_description = "Employee Attendance Report"
_inherit = "hr.employee.hour.report.abstract"
_auto = False # Will be processed in init method

type = fields.Selection(selection_add=TYPE_SELECTION, ondelete=ONDELETE_SELECTION)
check_in = fields.Datetime()
check_out = fields.Datetime()

def select_hook_custom_fields(self):
return """
SUM(heh.days_qty) AS days_qty_abs,
SUM(heh.hours_qty) AS hours_qty_abs,
SUM(heh.days_qty) AS days_qty,
SUM(heh.hours_qty) AS hours_qty,
heh.check_in,
heh.check_out,
"""

def where_types(self):
return ["attendance"]

def group_by_hook_custom_fields(self):
return "heh.check_in, heh.check_out,"
Loading

0 comments on commit faa69c2

Please sign in to comment.