Skip to content

[17.0][FIX+IMP] hr_holidays_natural_period: Hide Half day option in leaves if natural_day is selected + natural_day_half_day option #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions hr_holidays_natural_period/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Holidays natural period

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

This module was written to define natural day option in request unit on
holidays type.
This module was written to define natural day and natural day (Half Day)
options in request unit on holidays type.

**Table of contents**

Expand All @@ -44,8 +44,8 @@ For using natural period on leaves:
1. Go to *Leaves > Dashboard*.
2. Select dragging on the calendar the days you want to be on leave, or
go to the form view for selecting start and end dates.
3. Select the proper "Leave Type" that has "Natural day" selected in
"Request unit".
3. Select the proper "Leave Type" that has "Natural day" or "Natural day
(Half Day)" selected in "Request unit".
4. If no leave type is yet specified, then default configuration is to
exclude public holidays.
5. The number of days will be computed without employee calendar used.
Expand All @@ -71,19 +71,19 @@ Authors
Contributors
------------

- Tecnativa <https://www.tecnativa.com>
- Tecnativa <https://www.tecnativa.com>

- Víctor Martínez
- Pedro Baeza
- Carlos López
- Víctor Martínez
- Pedro Baeza
- Carlos López

- APSL-Nagarro <https://www.apsl.tech>
- APSL-Nagarro <https://www.apsl.tech>

- Antoni Marroig <[email protected]>
- Antoni Marroig <[email protected]>

- Grupo Isonor <https://www.grupoisonor.es>
- Grupo Isonor <https://www.grupoisonor.es>

- Alexandre D. Díaz
- Alexandre D. Díaz

Maintainers
-----------
Expand Down
1 change: 1 addition & 0 deletions hr_holidays_natural_period/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
"depends": ["hr_holidays"],
"maintainers": ["victoralmau"],
"demo": ["demo/hr_leave_type_data.xml"],
"data": ["views/hr_leave_views.xml"],
}
6 changes: 4 additions & 2 deletions hr_holidays_natural_period/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ def _get_consumed_leaves(self, leave_types, target_date=False, ignore_future=Fal
as hours.
"""
mod_leave_type_ids = self.env["hr.leave.type"]
leave_types_data = {}
for item in leave_types:
if item.request_unit == "natural_day":
if item.request_unit in ("natural_day", "natural_day_half_day"):
leave_types_data[item] = item.request_unit
item.sudo().request_unit = "day"
mod_leave_type_ids |= item
self = self.with_context(mod_holidays_status_ids=mod_leave_type_ids.ids)
res = super()._get_consumed_leaves(leave_types, target_date, ignore_future)
for item in mod_leave_type_ids:
item.sudo().request_unit = "natural_day"
item.sudo().request_unit = leave_types_data[item]
return res
6 changes: 4 additions & 2 deletions hr_holidays_natural_period/models/hr_leave.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ def _get_duration(self, check_leave_type=True, resource_calendar=None):
# to avoid the calculations being done as hours.
mod_holidays_status_ids = self.env.context.get("mod_holidays_status_ids", [])
is_mod_leave_type = self.holiday_status_id.id in mod_holidays_status_ids
old_request_unit = self.holiday_status_id.request_unit
is_request_unit_natural_day = is_mod_leave_type or (
self.holiday_status_id.request_unit == "natural_day"
self.holiday_status_id.request_unit
in ("natural_day", "natural_day_half_day")
)
instance = self.with_context(natural_period=is_request_unit_natural_day)
if is_request_unit_natural_day:
Expand All @@ -24,5 +26,5 @@ def _get_duration(self, check_leave_type=True, resource_calendar=None):
check_leave_type=check_leave_type, resource_calendar=resource_calendar
)
if is_request_unit_natural_day:
self.holiday_status_id.sudo().request_unit = "natural_day"
self.holiday_status_id.sudo().request_unit = old_request_unit
return res
5 changes: 4 additions & 1 deletion hr_holidays_natural_period/models/hr_leave_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ class HrLeaveAllocation(models.Model):

# Added option to this field because it is now computed (was related before).
type_request_unit = fields.Selection(
selection_add=[("natural_day", "Natural day")],
selection_add=[
("natural_day", "Natural day"),
("natural_day_half_day", "Natural day (Half Day)"),
],
)
7 changes: 5 additions & 2 deletions hr_holidays_natural_period/models/hr_leave_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class HrLeaveType(models.Model):
_inherit = "hr.leave.type"

request_unit = fields.Selection(
selection_add=[("natural_day", "Natural day")],
ondelete={"natural_day": "set default"},
selection_add=[
("natural_day", "Natural day"),
("natural_day_half_day", "Natural day (Half Day)"),
],
ondelete={"natural_day": "set default", "natural_day_half_day": "set default"},
)
3 changes: 1 addition & 2 deletions hr_holidays_natural_period/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
This module was written to define natural day option in request unit on
holidays type.
This module was written to define natural day and natural day (Half Day) options in request unit on holidays type.
4 changes: 2 additions & 2 deletions hr_holidays_natural_period/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ For using natural period on leaves:
1. Go to *Leaves \> Dashboard*.
2. Select dragging on the calendar the days you want to be on leave, or
go to the form view for selecting start and end dates.
3. Select the proper "Leave Type" that has "Natural day" selected in
"Request unit".
3. Select the proper "Leave Type" that has "Natural day" or "Natural day (Half Day)"
selected in "Request unit".
4. If no leave type is yet specified, then default configuration is to
exclude public holidays.
5. The number of days will be computed without employee calendar used.
8 changes: 4 additions & 4 deletions hr_holidays_natural_period/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ <h1 class="title">Holidays natural period</h1>
!! source digest: sha256:1d52c14dc289006977d27716f7d18d380e73c3102a60366ba31f58517fd37299
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/hr-holidays/tree/17.0/hr_holidays_natural_period"><img alt="OCA/hr-holidays" src="https://img.shields.io/badge/github-OCA%2Fhr--holidays-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/hr-holidays-17-0/hr-holidays-17-0-hr_holidays_natural_period"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/hr-holidays&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module was written to define natural day option in request unit on
holidays type.</p>
<p>This module was written to define natural day and natural day (Half Day)
options in request unit on holidays type.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -392,8 +392,8 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<li>Go to <em>Leaves &gt; Dashboard</em>.</li>
<li>Select dragging on the calendar the days you want to be on leave, or
go to the form view for selecting start and end dates.</li>
<li>Select the proper “Leave Type” that has “Natural day” selected in
“Request unit”.</li>
<li>Select the proper “Leave Type” that has “Natural day” or “Natural day
(Half Day)” selected in “Request unit”.</li>
<li>If no leave type is yet specified, then default configuration is to
exclude public holidays.</li>
<li>The number of days will be computed without employee calendar used.</li>
Expand Down
19 changes: 14 additions & 5 deletions hr_holidays_natural_period/tests/test_hr_leave.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# Copyright 2020-2025 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from freezegun import freeze_time

from odoo import fields
from odoo.tests import Form, new_test_user
from odoo.tests.common import users

from odoo.addons.base.tests.common import BaseCommon


@freeze_time("2023-01-01", tick=True)
class TestHrLeave(BaseCommon):
@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -82,7 +79,7 @@ def test_hr_leave_natural_day_01(self):
self.assertEqual(res_leave_type["max_leaves"], 5)
self.assertEqual(res_leave_type["leaves_taken"], 0)
self.assertEqual(res_leave_type["virtual_leaves_taken"], 0)
self.assertEqual(res_leave_type["request_unit"], "natural_day")
self.assertEqual(res_leave_type["request_unit"], self.leave_type.request_unit)
leave = self._create_hr_leave(self.leave_type, "2023-01-02", "2023-01-05")
self.assertEqual(leave.number_of_days, 4.0)
self.assertEqual(leave.number_of_days_display, 4.0)
Expand Down Expand Up @@ -115,8 +112,16 @@ def test_hr_leave_natural_day_02(self):
self.assertEqual(leave.number_of_days, 9.0)
self.assertEqual(leave.number_of_days_display, 9.0)

def test_hr_leave_natural_day_half_day_01(self):
self.leave_type.request_unit = "natural_day_half_day"
self.test_hr_leave_natural_day_01()

def test_hr_leave_natural_day_half_day_02(self):
self.leave_type.request_unit = "natural_day_half_day"
self.test_hr_leave_natural_day_02()

@users("test-user")
def test_hr_leave_day(self):
def test_hr_leave_day_01(self):
leave_allocation = self._create_leave_allocation(self.leave_type_day, 5)
leave_allocation.sudo().action_validate()
res_leave_type = (
Expand All @@ -133,3 +138,7 @@ def test_hr_leave_day(self):
leave = self._create_hr_leave(self.leave_type_day, "2023-01-08", "2023-01-15")
self.assertEqual(leave.number_of_days, 5)
self.assertEqual(leave.number_of_days_display, 5)

def test_hr_leave_day_02(self):
self.leave_type.request_unit = "natural_day_half_day"
self.test_hr_leave_day_01()
33 changes: 33 additions & 0 deletions hr_holidays_natural_period/views/hr_leave_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="hr_leave_view_form" model="ir.ui.view">
<field name="name">hr.leave.view.form</field>
<field name="model">hr.leave</field>
<field name="inherit_id" ref="hr_holidays.hr_leave_view_form" />
<field name="arch" type="xml">
<label for="number_of_days_display" position="attributes">
<attribute
name="invisible"
>request_unit_half and leave_type_request_unit not in ('hour', 'natural_day_half_day')</attribute>
</label>
<div name="duration_display" position="attributes">
<attribute
name="invisible"
>request_unit_half and leave_type_request_unit not in ('hour', 'natural_day_half_day')</attribute>
</div>
<label for="request_unit_half" position="attributes">
<attribute
name="invisible"
>leave_type_request_unit in ('day', 'natural_day')</attribute>
</label>
<xpath
expr="//label[@for='request_unit_half']/following-sibling::div"
position="attributes"
>
<attribute
name="invisible"
>leave_type_request_unit in ('day', 'natural_day')</attribute>
</xpath>
</field>
</record>
</odoo>