Skip to content

Commit

Permalink
[MIG] resource_calendar_get_days: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sonhd91 authored and xaviedoanhduy committed Aug 28, 2024
1 parent 26f2526 commit 8f3552d
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 701 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ addon | version | maintainers | summary
[hr_holidays_public](hr_holidays_public/) | 17.0.1.0.2 | | Manage Public Holidays
[hr_holidays_public_city](hr_holidays_public_city/) | 17.0.1.0.1 | [![victoralmau](https://github.com/victoralmau.png?size=30px)](https://github.com/victoralmau) | HR Holidays Public City
[hr_leave_custom_hour_interval](hr_leave_custom_hour_interval/) | 17.0.1.0.0 | | Edit start and end of leaves using time intervals
[resource_calendar_get_days](resource_calendar_get_days/) | 17.0.1.0.0 | | Calculate number of leave days relative to company working hours.

[//]: # (end addons)

Expand Down
674 changes: 0 additions & 674 deletions resource_calendar_get_days/LICENSE

This file was deleted.

91 changes: 73 additions & 18 deletions resource_calendar_get_days/README.rst
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.
5 changes: 4 additions & 1 deletion resource_calendar_get_days/__manifest__.py
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": """
Expand All @@ -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"],
Expand Down
22 changes: 15 additions & 7 deletions resource_calendar_get_days/models/hr_leave_allocation.py
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
)
5 changes: 4 additions & 1 deletion resource_calendar_get_days/models/resource_calendar.py
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
Expand All @@ -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)

Check warning on line 20 in resource_calendar_get_days/models/resource_calendar.py

View check run for this annotation

Codecov / codecov/patch

resource_calendar_get_days/models/resource_calendar.py#L20

Added line #L20 was not covered by tests
for start, stop, meta in intervals:
for start, stop, _ in intervals:
day_hours[start.date()] += (stop - start).total_seconds() / 3600

Check warning on line 22 in resource_calendar_get_days/models/resource_calendar.py

View check run for this annotation

Codecov / codecov/patch

resource_calendar_get_days/models/resource_calendar.py#L22

Added line #L22 was not covered by tests

# compute number of days as quarters
Expand Down
2 changes: 2 additions & 0 deletions resource_calendar_get_days/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Janik von Rotz <[email protected]>
* Son Ho <[email protected]>
5 changes: 5 additions & 0 deletions resource_calendar_get_days/readme/CREDITS.md
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.
1 change: 1 addition & 0 deletions resource_calendar_get_days/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Calculate number of leave days relative to company working hours.
1 change: 1 addition & 0 deletions resource_calendar_get_days/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_resource_calendar_get_days
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)

0 comments on commit 8f3552d

Please sign in to comment.