Skip to content

Commit

Permalink
[15.0][ADD] hr_timesheet_overview
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneMangin committed Dec 10, 2024
1 parent 0a7db2f commit c462755
Show file tree
Hide file tree
Showing 34 changed files with 2,245 additions and 0 deletions.
136 changes: 136 additions & 0 deletions hr_timesheet_overview/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
=====================
HR Timesheet Overview
=====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:dec11c63503653a4761c802a92d29169e6df3325b27e9f137da1fbfeba4433ac
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Ftimesheet-lightgray.png?logo=github
:target: https://github.com/OCA/timesheet/tree/15.0/hr_timesheet_overview
:alt: OCA/timesheet
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/timesheet-15-0/timesheet-15-0-hr_timesheet_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/timesheet&target_branch=15.0
:alt: Try me on Runboat

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

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

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

The main purpose of this dashboard is to allow employee and manager to have an overview of their working time according to their contract.

Two dashboard will be needed to have to axes of analyse and will cover the timesheet time and the contractual time of the employee

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

Dashboard Hours report
----------------------

The hours report will allow to calculate the under or over hours 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. The sum of the contractual hours, leaves and timesheet will give the time variation according to the contract.

The contractual hours should be calculated taking in account the following requirements:

- The 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)
- The 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 timesheet according to the contract time
- The timesheet section have the following requirement

- The timesheet time will be aggregated at project level (and not task as on the timesheet app)
- Working time and time off should be clearly separated (two columns)
- Time off are taken only if fully validated and from the leave object and timesheet created from a leave should be ignored (in order to avoid duplicates)
- By default we filter the current year until today and the user data.

Global requirement
------------------
The data coming from the timesheet and time off should always represent the situation we get if we go to the timesheet app or time off app (I mean by here that the data should be in real time). We accept that the data linked to the contract are updated every 24hours.

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

Security
--------

The employee should not see the data from the others employee.
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 hours
- Timesheet hours


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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/timesheet/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/timesheet/issues/new?body=module:%20hr_timesheet_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
~~~~~~~~~~~~

* Stéphane Mangin <[email protected]>
* Florent Xicluna <[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/timesheet <https://github.com/OCA/timesheet/tree/15.0/hr_timesheet_overview>`_ project on GitHub.

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

{
"name": "HR Timesheet Overview",
"version": "15.0.1.3.0",
"license": "AGPL-3",
"category": "Human Resources",
"website": "https://github.com/OCA/timesheet",
"author": "Camptocamp SA, Odoo Community Association (OCA)",
"depends": [
"board",
"hr",
"hr_contract",
"hr_timesheet",
],
"data": [
"security/ir.model.access.csv",
"views/menu_views.xml",
"views/hr_employee_hour_views.xml",
"wizards/hr_employee_hour_updater_view.xml",
"report/hr_employee_hour_report_views.xml",
],
"installable": True,
"auto_install": False,
}
72 changes: 72 additions & 0 deletions hr_timesheet_overview/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2023 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from datetime import datetime, timedelta

from odoo import fields

from odoo.addons.resource.models.resource import HOURS_PER_DAY

DEFAULT_TIME_QTY = {"hours_qty": HOURS_PER_DAY, "days_qty": 1.0, "type": "default"}


def get_end_of_day(date, attendances):
"""Returns the datetime corresponding to the end of the day"""
hour_to = max(attendances.mapped("hour_to"), default=0.0)
assert 0 <= hour_to < 24
time_part = datetime.utcfromtimestamp(hour_to * 60 * 60).time()
return datetime.combine(date, time_part)


def generate_dates_from_range(start_date, end_date=None):
"""Prepare a list of dates to be processed"""
if not end_date:
end_date = fields.Date.today()
deltas = range((end_date - start_date).days + 1)
return [start_date + timedelta(days=dt) for dt in deltas]


def get_attendances_values_by_date(employees, date_from=None, date_to=None):
"""Retrieve attendances (from resource module) values mapped by date
These attendances are the matrix product of contractual hours by day
and week days (NOT the `hr.attendance` model).
Warning: it is intended to be injected in context to reduce calls
:param employees: a list of employee records
:param date_from: a datetime.date object (default first contract date, included)
:param date_to: a datetime.date object (default today, included)
"""
values_by_date = {}
for employee in employees:
# Always set a value even empty to avoid mistreatment later on.
values_by_date[employee.id] = {}
contracts = employee.contract_ids
if not contracts:
continue
for contract in contracts:
custom_date_from = contract.date_start
custom_date_to = contract.date_end
if date_from:
custom_date_from = max(date_from, custom_date_from)
if date_to:
if custom_date_to:
custom_date_to = min(date_to, custom_date_to)
else:
custom_date_to = date_to
if custom_date_to and custom_date_to < custom_date_from:
continue
# Manage dates outside contract validity
if contract.date_end and custom_date_to > contract.date_end:
continue
if custom_date_from < contract.date_start:
continue

values = contract.prepare_hr_employee_hour_values(
date_start=custom_date_from, date_end=custom_date_to
)
values_by_date[employee.id].update(
[(hvals["date"], hvals) for hvals in values]
)
return values_by_date
Loading

0 comments on commit c462755

Please sign in to comment.