-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] hr_attendance_overtime_hours: Migration to 17.0
- Loading branch information
1 parent
1939f82
commit 7d81a50
Showing
10 changed files
with
178 additions
and
712 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,40 +1,86 @@ | ||
.. image:: https://img.shields.io/badge/licence-GPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/gpl-3.0-standalone.html | ||
:alt: License: GPL-3 | ||
|
||
============================ | ||
HR Attendance Overtime Hours | ||
============================ | ||
|
||
Show planned and worked hours in overtime view. | ||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:cc400dbb0880a74aca2a5acc0533e26549575d07261724ab7a8feeab4638c5b4 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/17.0/hr_attendance_overtime_hours | ||
: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-17-0/hr-attendance-17-0-hr_attendance_overtime_hours | ||
: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=17.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
Add Planned Hours/Worked Hours columns to the Overtime list view | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
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_overtime_hours%0Aversion:%2017.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 | ||
------- | ||
|
||
For a detailed documentation have a look at https://www.odoo-wiki.org/. | ||
* Mint System GmbH | ||
|
||
.. image:: https://raw.githubusercontent.com/Mint-System/Wiki/master/assets/icon-box.png | ||
:height: 100 | ||
:width: 100 | ||
:alt: Icon | ||
Contributors | ||
------------ | ||
|
||
Usage | ||
~~~~~ | ||
- Janik von Rotz [email protected] | ||
- Do Anh Duy [email protected] | ||
|
||
Clone module into Odoo addon directory. | ||
Other credits | ||
------------- | ||
|
||
.. code-block:: bash | ||
The original development of this module has been done by Mint System. It | ||
can be found in: | ||
https://github.com/Mint-System/Odoo-Apps-HR/blob/15.0/hr_attendance_overtime_hours | ||
|
||
git clone [email protected]:mint-system/odoo-app-hr-attendance-overtime-hours.git ./addons/hr_attendance_overtime_hours | ||
This module has been ported to the OCA with their agreement. | ||
|
||
Configuration | ||
~~~~~~~~~~~~~ | ||
Maintainers | ||
----------- | ||
|
||
* No additional configurations needed | ||
This module is maintained by the OCA. | ||
|
||
Maintainer | ||
========== | ||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
.. image:: https://raw.githubusercontent.com/Mint-System/Wiki/master/assets/mint-system-logo.png | ||
:target: https://www.mint-system.ch | ||
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 maintained by Mint System GmbH. | ||
This module is part of the `OCA/hr-attendance <https://github.com/OCA/hr-attendance/tree/17.0/hr_attendance_overtime_hours>`_ project on GitHub. | ||
|
||
For support and more information, please visit `our Website <https://www.mint-system.ch>`__. | ||
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Copyright 2023 Janik von Rotz <[email protected]> | ||
# Copyright 2024 Camptocamp | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
{ | ||
"name": "HR Attendance Overtime Hours", | ||
"summary": """ | ||
|
@@ -6,7 +9,7 @@ | |
"author": "Mint System GmbH, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/hr-attendance", | ||
"category": "Human Resources", | ||
"version": "15.0.1.0.0", | ||
"version": "17.0.1.0.0", | ||
"license": "AGPL-3", | ||
"depends": ["hr_attendance"], | ||
"data": ["views/hr_attendance_overtime.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 |
---|---|---|
@@ -1,20 +1,18 @@ | ||
import logging | ||
# Copyright 2023 Janik von Rotz <[email protected]> | ||
# Copyright 2024 Camptocamp | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
|
||
from datetime import datetime, time | ||
|
||
from odoo import api, fields, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class HrAttendanceOvertime(models.Model): | ||
_inherit = "hr.attendance.overtime" | ||
|
||
planned_hours = fields.Float( | ||
compute="_compute_planned_hours", store=True, readonly=True | ||
) | ||
worked_hours = fields.Float( | ||
compute="_compute_worked_hours", store=True, readonly=True | ||
) | ||
planned_hours = fields.Float(compute="_compute_planned_hours", store=True) | ||
worked_hours = fields.Float(compute="_compute_worked_hours", store=True) | ||
|
||
@api.depends("date") | ||
def _compute_planned_hours(self): | ||
|
@@ -32,12 +30,36 @@ def _compute_planned_hours(self): | |
@api.depends("duration") | ||
def _compute_worked_hours(self): | ||
for overtime in self: | ||
# Convert to UTC | ||
( | ||
datetime_check_in, | ||
datetime_check_out, | ||
) = overtime.convert_check_in_check_out_to_utc(overtime.date) | ||
# Get sum of attendance entries | ||
attendance_ids = self.env["hr.attendance"].search( | ||
attendance_ids = overtime.env["hr.attendance"].search( | ||
[ | ||
("employee_id", "=", overtime.employee_id.id), | ||
("check_in", ">=", datetime.combine(overtime.date, time.min)), | ||
("check_out", "<=", datetime.combine(overtime.date, time.max)), | ||
("check_in", ">=", datetime_check_in), | ||
("check_out", "<=", datetime_check_out), | ||
] | ||
) | ||
overtime.worked_hours = sum(attendance_ids.mapped("worked_hours")) | ||
|
||
def convert_check_in_check_out_to_utc(self, date_to_convert): | ||
tz = ( | ||
self.employee_id.resource_calendar_id.tz | ||
or self.employee_id.tz | ||
or self.env.user.tz | ||
) | ||
datetime_tz_check_in = datetime.combine(date_to_convert, time.min) | ||
datetime_tz_check_out = datetime.combine(date_to_convert, time.max) | ||
datetime_check_in = self._convert_str_to_datetime(datetime_tz_check_in, tz) | ||
datetime_check_out = self._convert_str_to_datetime(datetime_tz_check_out, tz) | ||
return datetime_check_in, datetime_check_out | ||
|
||
def _convert_str_to_datetime(self, datetime_to_tz, tz): | ||
return fields.Datetime.from_string( | ||
self.env["ir.fields.converter"] | ||
.with_context(tz=tz) | ||
._str_to_datetime(None, None, datetime_to_tz.replace(tzinfo=None))[0] | ||
) |
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 @@ | ||
* Janik von Rotz <[email protected]> | ||
* Do Anh Duy <[email protected]> |
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,4 @@ | ||
The original development of this module has been done by Mint System. | ||
It can be found in: https://github.com/Mint-System/Odoo-Apps-HR/blob/15.0/hr_attendance_overtime_hours | ||
|
||
This module has been ported to the OCA with their agreement. |
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 @@ | ||
Add Planned Hours/Worked Hours columns to the Overtime list view |
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 |
---|---|---|
|
@@ -32,4 +32,4 @@ <h3>Maintainer</h3> | |
</section> | ||
</section> | ||
</body> | ||
</html> | ||
</html> |
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 test_hr_attendance_overtime |
61 changes: 61 additions & 0 deletions
61
hr_attendance_overtime_hours/tests/test_hr_attendance_overtime.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,61 @@ | ||
# Copyright 2023 Janik von Rotz <[email protected]> | ||
# Copyright 2024 Camptocamp | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields | ||
from datetime import datetime, time | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestHRAttendanceOvertime(TransactionCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.calendar = cls.env['resource.calendar'].create({ | ||
'name': 'Test Calendar', | ||
'attendance_ids': [ | ||
(0, 0, { | ||
'name': 'Monday Morning', | ||
'dayofweek': '0', | ||
'hour_from': 8, | ||
'hour_to': 12, | ||
}), | ||
(0, 0, { | ||
'name': 'Monday Afternoon', | ||
'dayofweek': '0', | ||
'hour_from': 13, | ||
'hour_to': 17, | ||
}), | ||
], | ||
}) | ||
cls.employee = cls.env['hr.employee'].create({ | ||
'name': 'Test Employee', | ||
'resource_calendar_id': cls.calendar.id, | ||
}) | ||
cls.overtime = cls.env['hr.attendance.overtime'].create({ | ||
'employee_id': cls.employee.id, | ||
'date': fields.Date.today(), | ||
}) | ||
|
||
|
||
def test_compute_planned_hours(self): | ||
self.overtime._compute_planned_hours() | ||
self.assertEqual(self.overtime.planned_hours, 8.0) | ||
|
||
def test_compute_worked_hours(self): | ||
self.env['hr.attendance'].create( | ||
[ | ||
{ | ||
'employee_id': self.employee.id, | ||
'check_in': datetime.combine(self.overtime.date, time(8, 0)), | ||
'check_out': datetime.combine(self.overtime.date, time(12, 0)), | ||
}, | ||
{ | ||
'employee_id': self.employee.id, | ||
'check_in': datetime.combine(self.overtime.date, time(13, 0)), | ||
'check_out': datetime.combine(self.overtime.date, time(17, 0)), | ||
} | ||
] | ||
) | ||
self.overtime._compute_worked_hours() | ||
self.assertEqual(self.overtime.worked_hours, 8.0) |