[FIX] hr_holidays: take into account public holidays

Steps to reproduce:
-------------------
On the Time Off dashboard, click on a public holiday.

Issue:
------
The duration is 1 Day instead of zero day.

Cause:
------
To ignore the current holiday, the domain for finding holidays adds the condition:
```py
('holiday_id', '!=', self.id)
```

Unfortunately, if we have a `NewId`, in postgresql,
`NULL != NULL` condition always returns NULL.

As a result, public holidays (which do not have a `holiday_id`)
will not be taken into account.

Note:
This does not happen when you save because the id exists.

Solution:
---------
Accept `holiday_id` equal to `False` in the domain.

opw-3635949

closes odoo/odoo#151534

Signed-off-by: Sofie Gvaladze (sgv) <sgv@odoo.com>
This commit is contained in:
Thomas Lefebvre (thle)
2024-01-30 23:51:27 +00:00
parent 313b797e33
commit 3b470122f9
2 changed files with 47 additions and 2 deletions
+1 -1
View File
@@ -547,7 +547,7 @@ class HolidaysRequest(models.Model):
('company_id', 'in', self.env.companies.ids + self.env.context.get('allowed_company_ids', [])),
# When searching for resource leave intervals, we exclude the one that
# is related to the leave we're currently trying to compute for.
('holiday_id', '!=', self.id)]
'|', ('holiday_id', '=', False), ('holiday_id', '!=', self.id)]
if self.leave_type_request_unit == 'day' and check_leave_type:
# list of tuples (day, hours)
work_time_per_day_list = self.employee_id.list_work_time_per_day(self.date_from, self.date_to, calendar=resource_calendar, domain=domain)
+46 -1
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import date, datetime
from datetime import date, datetime, timedelta
from odoo.addons.hr_holidays.tests.common import TestHrHolidaysCommon
from odoo.exceptions import ValidationError
from freezegun import freeze_time
@@ -130,3 +130,48 @@ class TestGlobalLeaves(TestHrHolidaysCommon):
# Note:
# The user in Europe/Brussels timezone see 4:30 and not 2:30 because he is in UTC +02:00.
# The user in Asia/Calcutta timezone (determined via the browser) see 8:00 because he is in UTC +05:30
def test_global_leave_number_of_days_with_new(self):
"""
Check that leaves stored in memory (and not in the database)
take into account global leaves.
"""
global_leave = self.env['resource.calendar.leaves'].create({
'name': 'Global Time Off',
'date_from': datetime(2024, 1, 3, 6, 0, 0),
'date_to': datetime(2024, 1, 3, 19, 0, 0),
'calendar_id': self.calendar_1.id,
})
leave_type = self.env['hr.leave.type'].create({
'name': 'Paid Time Off',
'time_type': 'leave',
'requires_allocation': 'no',
})
self.employee_emp.resource_calendar_id = self.calendar_1.id
leave = self.env['hr.leave'].create({
'name': 'Test new leave',
'employee_id': self.employee_emp.id,
'holiday_status_id': leave_type.id,
'request_date_from': global_leave.date_from,
'request_date_to': global_leave.date_to,
})
self.assertEqual(leave.number_of_days, 0, 'It is a global leave')
leave = self.env['hr.leave'].new({
'name': 'Test new leave',
'employee_id': self.employee_emp.id,
'holiday_status_id': leave_type.id,
'request_date_from': global_leave.date_from,
'request_date_to': global_leave.date_to,
})
self.assertEqual(leave.number_of_days, 0, 'It is a global leave')
leave = self.env['hr.leave'].new({
'name': 'Test new leave',
'employee_id': self.employee_emp.id,
'holiday_status_id': leave_type.id,
'request_date_from': global_leave.date_from - timedelta(days=1),
'request_date_to': global_leave.date_to + timedelta(days=1),
})
self.assertEqual(leave.number_of_days, 2, 'There is a global leave')