Skip to content

Commit 32268a8

Browse files
[MIG] hr_holidays_natural_period: Migration to 19.0
1 parent 4640043 commit 32268a8

7 files changed

Lines changed: 80 additions & 79 deletions

File tree

hr_holidays_natural_period/README.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Holidays natural period
1111
!! This file is generated by oca-gen-addon-readme !!
1212
!! changes will be overwritten. !!
1313
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14-
!! source digest: sha256:103684da3f328a5df8849cf8b46061fa08a672c79f654f56ad91b475a13855ff
14+
!! source digest: sha256:d0c51197864f4aec9990179577b0bf2ee358dd0521d047fd699fd02ba8196bf9
1515
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1616
1717
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -21,13 +21,13 @@ Holidays natural period
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr--holidays-lightgray.png?logo=github
24-
:target: https://github.com/OCA/hr-holidays/tree/18.0/hr_holidays_natural_period
24+
:target: https://github.com/OCA/hr-holidays/tree/19.0/hr_holidays_natural_period
2525
:alt: OCA/hr-holidays
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/hr-holidays-18-0/hr-holidays-18-0-hr_holidays_natural_period
27+
:target: https://translation.odoo-community.org/projects/hr-holidays-19-0/hr-holidays-19-0-hr_holidays_natural_period
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/hr-holidays&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/hr-holidays&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -60,7 +60,7 @@ Bug Tracker
6060
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr-holidays/issues>`_.
6161
In case of trouble, please check there if your issue has already been reported.
6262
If you spotted it first, help us to smash it by providing a detailed and welcomed
63-
`feedback <https://github.com/OCA/hr-holidays/issues/new?body=module:%20hr_holidays_natural_period%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
63+
`feedback <https://github.com/OCA/hr-holidays/issues/new?body=module:%20hr_holidays_natural_period%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
6464

6565
Do not contact contributors directly about support or help with technical issues.
6666

@@ -110,6 +110,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
110110

111111
|maintainer-victoralmau|
112112

113-
This module is part of the `OCA/hr-holidays <https://github.com/OCA/hr-holidays/tree/18.0/hr_holidays_natural_period>`_ project on GitHub.
113+
This module is part of the `OCA/hr-holidays <https://github.com/OCA/hr-holidays/tree/19.0/hr_holidays_natural_period>`_ project on GitHub.
114114

115115
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

hr_holidays_natural_period/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Holidays natural period",
66
"summary": "Apply natural days in holidays",
7-
"version": "18.0.1.0.5",
7+
"version": "19.0.1.0.0",
88
"category": "Human Resources",
99
"website": "https://github.com/OCA/hr-holidays",
1010
"author": "Tecnativa, Odoo Community Association (OCA)",

hr_holidays_natural_period/demo/hr_leave_type_data.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<field name="name">Test Time Off (natural day)</field>
55
<field name="request_unit">natural_day</field>
66
<field name="responsible_ids" eval="[(4, ref('base.user_admin'))]" />
7-
<field name="employee_requests">yes</field>
7+
<field name="employee_requests">True</field>
88
</record>
99
</odoo>

hr_holidays_natural_period/models/resource_calendar.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
from odoo import models
1212
from odoo.tools.float_utils import float_round
13-
14-
from odoo.addons.resource.models.utils import Intervals
13+
from odoo.tools.intervals import Intervals
1514

1615

1716
class ResourceCalendar(models.Model):
@@ -40,7 +39,6 @@ def _get_attendance_intervals_days_data(self, attendance_intervals):
4039
interval_days = interval_hours / 24 # hours on a day
4140
day_hours[start.date()] += interval_hours
4241
day_days[start.date()] += interval_days
43-
4442
return {
4543
# Round the number of days to the closest 16th of a day.
4644
"days": float_round(
@@ -58,29 +56,26 @@ def _exist_interval_in_date(self, intervals, date):
5856
def _natural_period_intervals_batch(self, start_dt, end_dt, intervals, resources):
5957
# Re-define start_dt and end_dt to ensure that we always iterate through the
6058
# last day.
61-
start_dt = datetime.combine(start_dt.date(), time.min)
62-
end_time = (
63-
time.max
64-
if self.env.context.get("old_request_unit") == "natural_day"
65-
else time(12, 0, 0)
66-
)
67-
end_dt = datetime.combine(end_dt.date(), end_time)
59+
start_date = start_dt.date()
60+
end_date = end_dt.date()
61+
old_request_unit = self.env.context.get("old_request_unit")
62+
# Fix: if old_request_unit == 'day' and self.env.context.get('natural_period'):
63+
# old_request_unit = 'natural_day'
64+
if old_request_unit == "day" and self.env.context.get("natural_period"):
65+
old_request_unit = "natural_day"
66+
end_time = time.max if old_request_unit == "natural_day" else time(12, 0, 0)
6867
for resource in resources or []:
69-
interval_resource = intervals[resource.id]
7068
tz = timezone(resource.tz)
7169
attendances = []
72-
if len(interval_resource._items) > 0:
73-
attendances = interval_resource._items
74-
for day in rrule.rrule(rrule.DAILY, dtstart=start_dt, until=end_dt):
75-
exist_interval = self._exist_interval_in_date(attendances, day.date())
76-
if not exist_interval:
77-
attendances.append(
78-
(
79-
datetime.combine(day.date(), time.min).replace(tzinfo=tz),
80-
datetime.combine(day.date(), end_time).replace(tzinfo=tz),
81-
self.env["resource.calendar.attendance"],
82-
)
70+
# For natural days, create intervals for ALL days
71+
for day in rrule.rrule(rrule.DAILY, dtstart=start_date, until=end_date):
72+
attendances.append(
73+
(
74+
datetime.combine(day.date(), time.min).replace(tzinfo=tz),
75+
datetime.combine(day.date(), end_time).replace(tzinfo=tz),
76+
self.env["resource.calendar.attendance"],
8377
)
78+
)
8479
intervals[resource.id] = Intervals(attendances)
8580
return intervals
8681

hr_holidays_natural_period/static/description/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ <h1>Holidays natural period</h1>
372372
!! This file is generated by oca-gen-addon-readme !!
373373
!! changes will be overwritten. !!
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375-
!! source digest: sha256:103684da3f328a5df8849cf8b46061fa08a672c79f654f56ad91b475a13855ff
375+
!! source digest: sha256:d0c51197864f4aec9990179577b0bf2ee358dd0521d047fd699fd02ba8196bf9
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<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/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/hr-holidays/tree/18.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-18-0/hr-holidays-18-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=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<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/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/hr-holidays/tree/19.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-19-0/hr-holidays-19-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=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>This module was written to define natural day and natural day (Half Day)
379379
options in request unit on holidays type.</p>
380380
<p><strong>Table of contents</strong></p>
@@ -409,7 +409,7 @@ <h2><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h2>
409409
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/hr-holidays/issues">GitHub Issues</a>.
410410
In case of trouble, please check there if your issue has already been reported.
411411
If you spotted it first, help us to smash it by providing a detailed and welcomed
412-
<a class="reference external" href="https://github.com/OCA/hr-holidays/issues/new?body=module:%20hr_holidays_natural_period%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
412+
<a class="reference external" href="https://github.com/OCA/hr-holidays/issues/new?body=module:%20hr_holidays_natural_period%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
413413
<p>Do not contact contributors directly about support or help with technical issues.</p>
414414
</div>
415415
<div class="section" id="credits">
@@ -459,7 +459,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
459459
promote its widespread use.</p>
460460
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
461461
<p><a class="reference external image-reference" href="https://github.com/victoralmau"><img alt="victoralmau" src="https://github.com/victoralmau.png?size=40px" /></a></p>
462-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr-holidays/tree/18.0/hr_holidays_natural_period">OCA/hr-holidays</a> project on GitHub.</p>
462+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr-holidays/tree/19.0/hr_holidays_natural_period">OCA/hr-holidays</a> project on GitHub.</p>
463463
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
464464
</div>
465465
</div>

hr_holidays_natural_period/tests/test_hr_leave.py

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,23 @@ class TestHrLeave(BaseCommon):
1212
@classmethod
1313
def setUpClass(cls):
1414
super().setUpClass()
15-
cls.leave_type = cls.env.ref(
16-
"hr_holidays_natural_period.hr_leave_type_natural_day_test"
15+
cls.leave_type = cls.env["hr.leave.type"].create(
16+
{
17+
"name": "Natural Day Test Leave Type",
18+
"request_unit": "natural_day",
19+
"requires_allocation": True,
20+
"employee_requests": True,
21+
}
22+
)
23+
cls.leave_type_day = cls.env["hr.leave.type"].create(
24+
{
25+
"name": "Test Day Leave Type",
26+
"request_unit": "day",
27+
"requires_allocation": True,
28+
"employee_requests": True,
29+
}
1730
)
18-
cls.leave_type_day = cls.env.ref("hr_holidays.holiday_status_cl")
19-
cls.leave_type_day.employee_requests = "yes"
31+
2032
calendar = cls.env.ref("resource.resource_calendar_std")
2133
calendar = calendar.copy({"name": "Test calendar"})
2234
calendar.switch_calendar_type()
@@ -58,31 +70,35 @@ def _create_leave_allocation(self, leave_type, days):
5870
leave_allocation_form.number_of_days_display = days
5971
return leave_allocation_form.save()
6072

61-
def _create_hr_leave(self, leave_type, date_from, date_to):
73+
def _create_hr_leave(self, leave_type, date_from, date_to=None):
74+
if leave_type.request_unit == "natural_day_half_day":
75+
return self.env["hr.leave"].create(
76+
{
77+
"holiday_status_id": leave_type.id,
78+
"request_date_from": date_from,
79+
"request_date_to": date_to or date_from,
80+
"request_unit_half": True,
81+
"request_date_from_period": "am",
82+
"employee_id": self.employee.id,
83+
}
84+
)
85+
6286
leave_form = Form(self.env["hr.leave"])
6387
leave_form.holiday_status_id = leave_type
6488
leave_form.request_date_from = date_from
65-
if leave_type.request_unit == "natural_day_half_day":
66-
leave_form.request_unit_half = True
67-
leave_form.request_date_from_period = "am"
68-
else:
89+
if date_to:
6990
leave_form.request_date_to = date_to
7091
return leave_form.save()
7192

7293
def _test_hr_leave_natural_day_01(self):
7394
leave_allocation = self._create_leave_allocation(self.leave_type, 5)
74-
leave_allocation.sudo().action_validate()
75-
res_leave_type = (
76-
self.env["hr.leave.type"]
77-
.with_company(self.env.company)
78-
.get_allocation_data_request()[0][1]
95+
leave_allocation.sudo()._action_validate()
96+
97+
self.assertEqual(leave_allocation.number_of_days, 5)
98+
self.assertEqual(
99+
self.leave_type.request_unit in ("natural_day", "natural_day_half_day"),
100+
True,
79101
)
80-
self.assertEqual(res_leave_type["remaining_leaves"], 5)
81-
self.assertEqual(res_leave_type["virtual_remaining_leaves"], 5)
82-
self.assertEqual(res_leave_type["max_leaves"], 5)
83-
self.assertEqual(res_leave_type["leaves_taken"], 0)
84-
self.assertEqual(res_leave_type["virtual_leaves_taken"], 0)
85-
self.assertEqual(res_leave_type["request_unit"], self.leave_type.request_unit)
86102

87103
@users("test-user")
88104
@mute_logger("odoo.models.unlink")
@@ -96,7 +112,7 @@ def test_hr_leave_natural_day_01(self):
96112
def test_hr_leave_natural_day_half_day_01(self):
97113
self.leave_type.request_unit = "natural_day_half_day"
98114
self._test_hr_leave_natural_day_01()
99-
leave = self._create_hr_leave(self.leave_type, "2023-01-02", "2023-01-05")
115+
leave = self._create_hr_leave(self.leave_type, "2023-01-02")
100116
self.assertEqual(leave.number_of_days, 0.5)
101117

102118
def _test_hr_leave_natural_day_02(self):
@@ -125,7 +141,7 @@ def _test_hr_leave_natural_day_02(self):
125141
)
126142
self.employee.resource_calendar_id = calendar
127143
leave_allocation = self._create_leave_allocation(self.leave_type, 9)
128-
leave_allocation.sudo().action_validate()
144+
leave_allocation.sudo()._action_validate()
129145

130146
@users("test-user")
131147
@mute_logger("odoo.models.unlink")
@@ -139,24 +155,16 @@ def test_hr_leave_natural_day_02(self):
139155
def test_hr_leave_natural_day_half_day_02(self):
140156
self.leave_type.request_unit = "natural_day_half_day"
141157
self._test_hr_leave_natural_day_02()
142-
leave = self._create_hr_leave(self.leave_type, "2023-01-01", "2023-01-09")
158+
leave = self._create_hr_leave(self.leave_type, "2023-01-01")
143159
self.assertEqual(leave.number_of_days, 0.5)
144160

145161
@users("test-user")
146162
@mute_logger("odoo.models.unlink")
147163
def test_hr_leave_day(self):
148164
leave_allocation = self._create_leave_allocation(self.leave_type_day, 5)
149-
leave_allocation.sudo().action_validate()
150-
res_leave_type = (
151-
self.env["hr.leave.type"]
152-
.with_company(self.env.company)
153-
.get_allocation_data_request()[0][1]
154-
)
155-
self.assertEqual(res_leave_type["remaining_leaves"], 5)
156-
self.assertEqual(res_leave_type["virtual_remaining_leaves"], 5)
157-
self.assertEqual(res_leave_type["max_leaves"], 5)
158-
self.assertEqual(res_leave_type["leaves_taken"], 0)
159-
self.assertEqual(res_leave_type["virtual_leaves_taken"], 0)
160-
self.assertEqual(res_leave_type["request_unit"], "day")
165+
leave_allocation.sudo()._action_validate()
166+
167+
self.assertEqual(leave_allocation.number_of_days, 5)
168+
self.assertEqual(self.leave_type_day.request_unit, "day")
161169
leave = self._create_hr_leave(self.leave_type_day, "2023-01-08", "2023-01-15")
162170
self.assertEqual(leave.number_of_days, 5)

hr_holidays_natural_period/views/hr_leave_views.xml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@
55
<field name="model">hr.leave</field>
66
<field name="inherit_id" ref="hr_holidays.hr_leave_view_form" />
77
<field name="arch" type="xml">
8-
<label for="request_unit_half" position="attributes">
9-
<attribute
10-
name="invisible"
11-
>leave_type_request_unit in ('day', 'natural_day')</attribute>
12-
</label>
138
<xpath
14-
expr="//label[@for='request_unit_half']/following-sibling::div"
9+
expr="//div[hasclass('o_row')]/field[@name='request_date_from_period']"
1510
position="attributes"
1611
>
1712
<attribute
1813
name="invisible"
19-
>leave_type_request_unit in ('day', 'natural_day')</attribute>
14+
>leave_type_request_unit in ('day', 'natural_day') or not request_unit_half</attribute>
2015
</xpath>
21-
<field name="request_unit_half" position="attributes">
16+
<xpath
17+
expr="//div[hasclass('o_row')]/field[@name='request_date_to_period']"
18+
position="attributes"
19+
>
2220
<attribute
2321
name="invisible"
24-
>leave_type_request_unit in ('day', 'natural_day')</attribute>
25-
</field>
22+
>leave_type_request_unit in ('day', 'natural_day') or not request_unit_half</attribute>
23+
</xpath>
2624
</field>
2725
</record>
2826
</odoo>

0 commit comments

Comments
 (0)