-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] resource_calendar_get_days: Migration to 17.0
- Loading branch information
1 parent
26f2526
commit 8f3552d
Showing
11 changed files
with
145 additions
and
701 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
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,31 +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 | ||
|
||
========================== | ||
Resource Calendar Get Days | ||
========================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:1043aee66e88d5c33bfa9031750b3cb4440d8e697dde4fd31e885f20d70f9490 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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--holidays-lightgray.png?logo=github | ||
:target: https://github.com/OCA/hr-holidays/tree/17.0/resource_calendar_get_days | ||
:alt: OCA/hr-holidays | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/hr-holidays-17-0/hr-holidays-17-0-resource_calendar_get_days | ||
: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-holidays&target_branch=17.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
Calculate number of leave days relative to company working hours. | ||
|
||
For a detailed documentation have a look at https://www.odoo-wiki.org/. | ||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr-holidays/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-holidays/issues/new?body=module:%20resource_calendar_get_days%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 | ||
------- | ||
|
||
* Mint System GmbH | ||
|
||
Contributors | ||
------------ | ||
|
||
- Janik von Rotz [email protected] | ||
- Son Ho [email protected] | ||
|
||
Other credits | ||
------------- | ||
|
||
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/tree/15.0/resource_calendar_get_days | ||
|
||
.. image:: https://raw.githubusercontent.com/Mint-System/Wiki/master/assets/icon-box.png | ||
:height: 100 | ||
:width: 100 | ||
:alt: Icon | ||
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-holidays <https://github.com/OCA/hr-holidays/tree/17.0/resource_calendar_get_days>`_ 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 2024 Janik von Rotz <[email protected]> | ||
# Copyright 2024 Camptocamp | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
{ | ||
"name": "Resource Calendar Get Days", | ||
"summary": """ | ||
|
@@ -6,7 +9,7 @@ | |
"author": "Mint System GmbH, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/hr-holidays", | ||
"category": "Human Resources", | ||
"version": "14.0.2.0.0", | ||
"version": "17.0.1.0.0", | ||
"license": "AGPL-3", | ||
"demo": ["demo/resource_data.xml"], | ||
"depends": ["hr_holidays"], | ||
|
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,16 +1,24 @@ | ||
# Copyright 2024 Janik von Rotz <[email protected]> | ||
# Copyright 2024 Camptocamp | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from odoo import api, models | ||
|
||
from odoo.addons.resource.models.utils import HOURS_PER_DAY | ||
|
||
|
||
class HolidaysAllocation(models.Model): | ||
_inherit = "hr.leave.allocation" | ||
|
||
@api.depends("number_of_days", "employee_id") | ||
@api.depends("number_of_days", "holiday_status_id", "employee_id", "holiday_type") | ||
def _compute_number_of_hours_display(self): | ||
for allocation in self: | ||
if allocation.number_of_days: | ||
allocation.number_of_hours_display = ( | ||
allocation.number_of_days | ||
* allocation.employee_id.sudo().resource_id.calendar_id.hours_per_day | ||
allocation_calendar = ( | ||
allocation.holiday_status_id.company_id.resource_calendar_id | ||
) | ||
if allocation.holiday_type == "employee" and allocation.employee_id: | ||
allocation_calendar = ( | ||
allocation.employee_id.sudo().resource_id.calendar_id | ||
) | ||
else: | ||
allocation.number_of_hours_display = 0.0 | ||
allocation.number_of_hours_display = allocation.number_of_days * ( | ||
allocation_calendar.hours_per_day or HOURS_PER_DAY | ||
) |
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 2024 Janik von Rotz <[email protected]> | ||
# Copyright 2024 Camptocamp | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from collections import defaultdict | ||
|
||
from odoo import models | ||
|
@@ -15,7 +18,7 @@ def _get_days_data(self, intervals, day_total): | |
OVERWRITE: Calculate number of days against company hours per day. | ||
""" | ||
day_hours = defaultdict(float) | ||
for start, stop, meta in intervals: | ||
for start, stop, _ in intervals: | ||
day_hours[start.date()] += (stop - start).total_seconds() / 3600 | ||
|
||
# compute number of days as quarters | ||
|
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]> | ||
* Son Ho <[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,5 @@ | ||
|
||
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/tree/15.0/resource_calendar_get_days | ||
|
||
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 @@ | ||
Calculate number of leave days relative to company working 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 test_resource_calendar_get_days |
39 changes: 39 additions & 0 deletions
39
resource_calendar_get_days/tests/test_resource_calendar_get_days.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,39 @@ | ||
# Copyright 2024 Camptocamp | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo.addons.hr_holidays.tests.common import TestHrHolidaysCommon | ||
|
||
|
||
class TestResourceCalendarGetDays(TestHrHolidaysCommon): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.leave_type = cls.env["hr.leave.type"].create( | ||
{ | ||
"name": "Time Off with no validation for approval", | ||
"time_type": "leave", | ||
"requires_allocation": "yes", | ||
"allocation_validation_type": "no", | ||
} | ||
) | ||
|
||
cls.employee_emp.resource_calendar_id = cls.env.ref( | ||
"resource_calendar_get_days.resource_calendar_std_42h" | ||
).id | ||
|
||
def test_resource_calendar_get_days_effect_allocation(self): | ||
emp_allocation = self.env["hr.leave.allocation"].create( | ||
{ | ||
"name": "Bank Holiday", | ||
"holiday_type": "employee", | ||
"employee_ids": [(4, self.employee_emp.id)], | ||
"employee_id": self.employee_emp.id, | ||
"date_from": "2024-06-17", | ||
"holiday_status_id": self.leave_type.id, | ||
"number_of_days": 3, | ||
"allocation_type": "regular", | ||
} | ||
) | ||
emp_allocation.action_validate() | ||
# 3 days * 8.4 hour/day ~ 25.2 | ||
self.assertEqual(round(emp_allocation.number_of_hours_display, 2), 25.2) |