-
-
Notifications
You must be signed in to change notification settings - Fork 334
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_timesheet_sheet_employee_calendar_planning
- Loading branch information
1 parent
a012110
commit fbd50c0
Showing
15 changed files
with
1,446 additions
and
0 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
hr_timesheet_sheet_employee_calendar_planning/README.rst
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,103 @@ | ||
============================================= | ||
HR Timesheet Sheet Employee Calendar Planning | ||
============================================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:09a3d0d21568cc920fdf9c821a2f6470b741c049044c4e7e26e6a33cd71e6026 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/16.0/hr_timesheet_sheet_employee_calendar_planning | ||
:alt: OCA/timesheet | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/timesheet-16-0/timesheet-16-0-hr_timesheet_sheet_employee_calendar_planning | ||
: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=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module evaluates a set of quality requirements related to Timesheet Sheets. | ||
For each sheet, using its employee's calendar plannings | ||
(and their associated working time specifications) it computes the theoretical | ||
working time for each day in the sheet and compares it with the real working time, | ||
present in the actual sheet. | ||
|
||
The requirements it evaluates are: | ||
|
||
* Invalid hours per day: The employee's imputed hours for one or more days | ||
deviate from the theoretical hours for those specific days. | ||
* Invalid hours per week: The employee's imputed hours for an entire week | ||
differ from the theoretical hours for that week. | ||
* Hours on non working day: Flags situations where employees have | ||
recorded hours on a day designated as a non-working day. | ||
|
||
The requirements are later available in the class as boolean fields. | ||
With this information, Timesheet Sheets submitters and reviewers can have a better | ||
idea about the consistency of the imputed work hours with the calendar that they should adhere to. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Installation | ||
============ | ||
|
||
This module relies on: | ||
|
||
* The OCA module '2D matrix for x2many fields', and can be downloaded from | ||
Github: https://github.com/OCA/web/tree/16.0/web_widget_x2many_2d_matrix | ||
* The OCA module 'Employee Calendar Planning', and can be downloaded from | ||
Github: https://github.com/OCA/hr/tree/16.0/hr_employee_calendar_planning | ||
|
||
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_sheet_employee_calendar_planning%0Aversion:%2016.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 | ||
~~~~~~~ | ||
|
||
* ForgeFlow | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Laura Cazorla <laura.cazorla@forgeflow.com> | ||
|
||
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/16.0/hr_timesheet_sheet_employee_calendar_planning>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import models |
16 changes: 16 additions & 0 deletions
16
hr_timesheet_sheet_employee_calendar_planning/__manifest__.py
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,16 @@ | ||
# Copyright 2024 ForgeFlow (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "HR Timesheet Sheet Employee Calendar Planning", | ||
"version": "16.0.1.0.0", | ||
"category": "Human Resources", | ||
"summary": "Timesheet Sheets, Activities", | ||
"license": "AGPL-3", | ||
"author": "ForgeFlow, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/timesheet", | ||
"installable": True, | ||
"auto_install": False, | ||
"depends": ["hr_timesheet_sheet", "hr_employee_calendar_planning"], | ||
"data": [], | ||
} |
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,58 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * hr_timesheet_sheet_employee_calendar_planning | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0+e\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-03-14 08:31+0000\n" | ||
"PO-Revision-Date: 2024-03-14 08:31+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_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model.fields,field_description:hr_timesheet_sheet_employee_calendar_planning.field_hr_timesheet_sheet__hours_no_working_day | ||
msgid "Hours No Working Day" | ||
msgstr "Horas En Día De Descanso" | ||
|
||
#. module: hr_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model.fields,field_description:hr_timesheet_sheet_employee_calendar_planning.field_hr_timesheet_sheet__invalid_hours_per_day | ||
msgid "Invalid Hours Per Day" | ||
msgstr "Horas Diarias Inválidas" | ||
|
||
#. module: hr_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model.fields,field_description:hr_timesheet_sheet_employee_calendar_planning.field_hr_timesheet_sheet__invalid_hours_per_week | ||
msgid "Invalid Hours Per Week" | ||
msgstr "Horas Semanales Inválidas" | ||
|
||
#. module: hr_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model.fields,help:hr_timesheet_sheet_employee_calendar_planning.field_hr_timesheet_sheet__hours_no_working_day | ||
msgid "" | ||
"The employee has imputed hours on a day where they're not supposed to work." | ||
msgstr "El empleado ha imputado horas en un día en el que no debería trabajar." | ||
|
||
#. module: hr_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model.fields,help:hr_timesheet_sheet_employee_calendar_planning.field_hr_timesheet_sheet__invalid_hours_per_week | ||
msgid "" | ||
"The employee's imputed hours for a whole week differ from its theoretical " | ||
"hours for that week." | ||
msgstr "Las horas del empleado imputadas para una semana difieren de sus horas " | ||
"teóricas para esa semana." | ||
|
||
#. module: hr_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model.fields,help:hr_timesheet_sheet_employee_calendar_planning.field_hr_timesheet_sheet__invalid_hours_per_day | ||
msgid "" | ||
"The employee's imputed hours for one or more days differ from its " | ||
"theoretical hours for those days." | ||
msgstr "Las horas del empleado imputadas para uno o más días difieren de sus " | ||
"horas teóricas para esos días." | ||
|
||
#. module: hr_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model,name:hr_timesheet_sheet_employee_calendar_planning.model_hr_timesheet_sheet | ||
msgid "Timesheet Sheet" | ||
msgstr "Hoja de Servicios" |
56 changes: 56 additions & 0 deletions
56
...t_sheet_employee_calendar_planning/i18n/hr_timesheet_sheet_employee_calendar_planning.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,56 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * hr_timesheet_sheet_employee_calendar_planning | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0+e\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-03-14 08:30+0000\n" | ||
"PO-Revision-Date: 2024-03-14 08:30+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_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model.fields,field_description:hr_timesheet_sheet_employee_calendar_planning.field_hr_timesheet_sheet__hours_no_working_day | ||
msgid "Hours No Working Day" | ||
msgstr "" | ||
|
||
#. module: hr_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model.fields,field_description:hr_timesheet_sheet_employee_calendar_planning.field_hr_timesheet_sheet__invalid_hours_per_day | ||
msgid "Invalid Hours Per Day" | ||
msgstr "" | ||
|
||
#. module: hr_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model.fields,field_description:hr_timesheet_sheet_employee_calendar_planning.field_hr_timesheet_sheet__invalid_hours_per_week | ||
msgid "Invalid Hours Per Week" | ||
msgstr "" | ||
|
||
#. module: hr_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model.fields,help:hr_timesheet_sheet_employee_calendar_planning.field_hr_timesheet_sheet__hours_no_working_day | ||
msgid "" | ||
"The employee has imputed hours on a day where they're not supposed to work." | ||
msgstr "" | ||
|
||
#. module: hr_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model.fields,help:hr_timesheet_sheet_employee_calendar_planning.field_hr_timesheet_sheet__invalid_hours_per_week | ||
msgid "" | ||
"The employee's imputed hours for a whole week differ from its theoretical " | ||
"hours for that week." | ||
msgstr "" | ||
|
||
#. module: hr_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model.fields,help:hr_timesheet_sheet_employee_calendar_planning.field_hr_timesheet_sheet__invalid_hours_per_day | ||
msgid "" | ||
"The employee's imputed hours for one or more days differ from its " | ||
"theoretical hours for those days." | ||
msgstr "" | ||
|
||
#. module: hr_timesheet_sheet_employee_calendar_planning | ||
#: model:ir.model,name:hr_timesheet_sheet_employee_calendar_planning.model_hr_timesheet_sheet | ||
msgid "Timesheet Sheet" | ||
msgstr "" |
3 changes: 3 additions & 0 deletions
3
hr_timesheet_sheet_employee_calendar_planning/models/__init__.py
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,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import hr_timesheet_sheet |
117 changes: 117 additions & 0 deletions
117
hr_timesheet_sheet_employee_calendar_planning/models/hr_timesheet_sheet.py
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,117 @@ | ||
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
from datetime import datetime, timedelta | ||
|
||
from pytz import utc | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class Sheet(models.Model): | ||
_inherit = "hr_timesheet.sheet" | ||
|
||
invalid_hours_per_day = fields.Boolean( | ||
compute="_compute_invalid_imputations", | ||
default=False, | ||
help="The employee's imputed hours for one or more days differ from " | ||
"its theoretical hours for those days.", | ||
) | ||
invalid_hours_per_week = fields.Boolean( | ||
compute="_compute_invalid_imputations", | ||
default=False, | ||
help="The employee's imputed hours for a whole week differ from its " | ||
"theoretical hours for that week.", | ||
) | ||
hours_no_working_day = fields.Boolean( | ||
compute="_compute_invalid_imputations", | ||
default=False, | ||
help="The employee has imputed hours on a day where they're not " | ||
"supposed to work.", | ||
) | ||
|
||
def _compute_invalid_imputations(self): | ||
for sheet in self: | ||
theoretical_weekly_hours = sheet._calculate_theoretical_hours() | ||
real_weekly_hours = sheet._calculate_real_hours() | ||
|
||
sheet.invalid_hours_per_day = False | ||
sheet.hours_no_working_day = False | ||
sheet.invalid_hours_per_week = False | ||
|
||
for week_index in range(len(real_weekly_hours)): | ||
for weekday_index in range(7): | ||
if ( | ||
theoretical_weekly_hours[week_index][weekday_index] | ||
!= real_weekly_hours[week_index][weekday_index] | ||
): | ||
sheet.invalid_hours_per_day = True | ||
if theoretical_weekly_hours[week_index][weekday_index] == 0: | ||
sheet.hours_no_working_day = True | ||
if sum(theoretical_weekly_hours[week_index].values()) != sum( | ||
real_weekly_hours[week_index].values() | ||
): | ||
sheet.invalid_hours_per_week = True | ||
|
||
def _calculate_theoretical_hours(self): | ||
"""Get number of theoretical hours for each day in the sheet. | ||
We work with complete weeks, so if a timesheet ends on Friday we will get | ||
0 hours for Saturday and Sunday. To compute them, we use the employee's | ||
personal resource_calendar in the sheet's time span.""" | ||
self.ensure_one() | ||
monday1, week_num = self.get_sheet_weeks_num() | ||
theoretical_weekly_hours = { | ||
week: {index: 0 for index in range(7)} for week in range(week_num) | ||
} | ||
|
||
employee = self.employee_id | ||
calendar = employee.resource_calendar_id | ||
start_date = datetime.combine(self.date_start, datetime.min.time()).replace( | ||
tzinfo=utc | ||
) | ||
end_date = datetime.combine(self.date_end, datetime.max.time()).replace( | ||
tzinfo=utc | ||
) | ||
intervals = calendar._work_intervals_batch( | ||
start_date, end_date, employee.resource_id, compute_leaves=True | ||
) | ||
|
||
for start, stop, _meta in intervals[employee.resource_id.id]: | ||
date = start.date() | ||
week = (date - monday1).days // 7 | ||
weekday = date.weekday() | ||
hours_sum = (stop - start).total_seconds() / 3600 | ||
theoretical_weekly_hours[week][weekday] += hours_sum | ||
|
||
return theoretical_weekly_hours | ||
|
||
def _calculate_real_hours(self): | ||
"""Get number of real hours for each day in the sheet. We work with complete weeks, | ||
so if a timesheet ends on Friday we will get 0 hours for Saturday and Sunday.""" | ||
self.ensure_one() | ||
monday1, week_num = self.get_sheet_weeks_num() | ||
real_weekly_hours = { | ||
week: {index: 0 for index in range(7)} for week in range(week_num) | ||
} | ||
|
||
for line in self.timesheet_ids: | ||
day_of_week = line.date.weekday() | ||
week = (line.date - monday1).days // 7 | ||
if hasattr(line, "holiday_id") and hasattr(line, "global_leave_id"): | ||
if not line.holiday_id and not line.global_leave_id: | ||
real_weekly_hours[week][day_of_week] += line.unit_amount | ||
else: | ||
real_weekly_hours[week][day_of_week] += line.unit_amount | ||
return real_weekly_hours | ||
|
||
def get_sheet_weeks_num(self): | ||
"""Get number of weeks between sheet's date_start and date_end. Weeks start on | ||
Monday and end on Sunday. | ||
Example: If the sheet goes from Friday to next Monday, that counts as | ||
2 weeks (since the dates belong to 2 different weeks).""" | ||
self.ensure_one() | ||
dt1 = self.date_start | ||
dt2 = self.date_end | ||
monday1 = dt1 - timedelta(days=dt1.weekday()) | ||
monday2 = dt2 - timedelta(days=dt2.weekday()) | ||
return monday1, (monday2 - monday1).days // 7 + 1 |
1 change: 1 addition & 0 deletions
1
hr_timesheet_sheet_employee_calendar_planning/readme/CONTRIBUTORS.rst
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 @@ | ||
* Laura Cazorla <laura.cazorla@forgeflow.com> |
18 changes: 18 additions & 0 deletions
18
hr_timesheet_sheet_employee_calendar_planning/readme/DESCRIPTION.rst
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 @@ | ||
This module evaluates a set of quality requirements related to Timesheet Sheets. | ||
For each sheet, using its employee's calendar plannings | ||
(and their associated working time specifications) it computes the theoretical | ||
working time for each day in the sheet and compares it with the real working time, | ||
present in the actual sheet. | ||
|
||
The requirements it evaluates are: | ||
|
||
* Invalid hours per day: The employee's imputed hours for one or more days | ||
deviate from the theoretical hours for those specific days. | ||
* Invalid hours per week: The employee's imputed hours for an entire week | ||
differ from the theoretical hours for that week. | ||
* Hours on non working day: Flags situations where employees have | ||
recorded hours on a day designated as a non-working day. | ||
|
||
The requirements are later available in the class as boolean fields. | ||
With this information, Timesheet Sheets submitters and reviewers can have a better | ||
idea about the consistency of the imputed work hours with the calendar that they should adhere to. |
6 changes: 6 additions & 0 deletions
6
hr_timesheet_sheet_employee_calendar_planning/readme/INSTALL.rst
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 @@ | ||
This module relies on: | ||
|
||
* The OCA module '2D matrix for x2many fields', and can be downloaded from | ||
Github: https://github.com/OCA/web/tree/16.0/web_widget_x2many_2d_matrix | ||
* The OCA module 'Employee Calendar Planning', and can be downloaded from | ||
Github: https://github.com/OCA/hr/tree/16.0/hr_employee_calendar_planning |
Oops, something went wrong.