[IMP] hr_holidays_timeoff_analysis : apply changes proposed by pre-commit
This commit is contained in:
@@ -1,3 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import test_hr_leave_timeoff_day
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo.fields import Date
|
||||
from odoo.tests import tagged
|
||||
from odoo.tests.common import TransactionCase
|
||||
@@ -96,21 +95,123 @@ class TestHrLeaveTimeoffDay(TransactionCase):
|
||||
)
|
||||
|
||||
def test_leave_duration_by_day_hour_compare_to_employee_calendar(self):
|
||||
employee_calendar = self.env['resource.calendar'].create({
|
||||
'name': 'Employee Calendar',
|
||||
'attendance_ids': [
|
||||
(0, 0, {'name': 'Monday Morning', 'dayofweek': '0', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Monday Afternoon', 'dayofweek': '0', 'hour_from': 13, 'hour_to': 17, 'day_period': 'afternoon'}),
|
||||
(0, 0, {'name': 'Tuesday Morning', 'dayofweek': '1', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Tuesday Afternoon', 'dayofweek': '1', 'hour_from': 13, 'hour_to': 17, 'day_period': 'afternoon'}),
|
||||
(0, 0, {'name': 'Wednesday Morning', 'dayofweek': '2', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Wednesday Afternoon', 'dayofweek': '2', 'hour_from': 13, 'hour_to': 17, 'day_period': 'afternoon'}),
|
||||
(0, 0, {'name': 'Thursday Morning', 'dayofweek': '3', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Thursday Afternoon', 'dayofweek': '3', 'hour_from': 13, 'hour_to': 17, 'day_period': 'afternoon'}),
|
||||
(0, 0, {'name': 'Friday Morning', 'dayofweek': '4', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Friday Afternoon', 'dayofweek': '4', 'hour_from': 13, 'hour_to': 17, 'day_period': 'afternoon'}),
|
||||
],
|
||||
})
|
||||
employee_calendar = self.env["resource.calendar"].create(
|
||||
{
|
||||
"name": "Employee Calendar",
|
||||
"attendance_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Monday Morning",
|
||||
"dayofweek": "0",
|
||||
"hour_from": 8,
|
||||
"hour_to": 12,
|
||||
"day_period": "morning",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Monday Afternoon",
|
||||
"dayofweek": "0",
|
||||
"hour_from": 13,
|
||||
"hour_to": 17,
|
||||
"day_period": "afternoon",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Tuesday Morning",
|
||||
"dayofweek": "1",
|
||||
"hour_from": 8,
|
||||
"hour_to": 12,
|
||||
"day_period": "morning",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Tuesday Afternoon",
|
||||
"dayofweek": "1",
|
||||
"hour_from": 13,
|
||||
"hour_to": 17,
|
||||
"day_period": "afternoon",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Wednesday Morning",
|
||||
"dayofweek": "2",
|
||||
"hour_from": 8,
|
||||
"hour_to": 12,
|
||||
"day_period": "morning",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Wednesday Afternoon",
|
||||
"dayofweek": "2",
|
||||
"hour_from": 13,
|
||||
"hour_to": 17,
|
||||
"day_period": "afternoon",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Thursday Morning",
|
||||
"dayofweek": "3",
|
||||
"hour_from": 8,
|
||||
"hour_to": 12,
|
||||
"day_period": "morning",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Thursday Afternoon",
|
||||
"dayofweek": "3",
|
||||
"hour_from": 13,
|
||||
"hour_to": 17,
|
||||
"day_period": "afternoon",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Friday Morning",
|
||||
"dayofweek": "4",
|
||||
"hour_from": 8,
|
||||
"hour_to": 12,
|
||||
"day_period": "morning",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Friday Afternoon",
|
||||
"dayofweek": "4",
|
||||
"hour_from": 13,
|
||||
"hour_to": 17,
|
||||
"day_period": "afternoon",
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
)
|
||||
self.employee.resource_calendar_id = employee_calendar
|
||||
|
||||
leave = self.env["hr.leave"].create(
|
||||
@@ -119,7 +220,7 @@ class TestHrLeaveTimeoffDay(TransactionCase):
|
||||
"request_date_from": Date.to_date("2025-07-03"),
|
||||
"request_date_to": Date.to_date("2025-07-03"),
|
||||
"request_unit_hours": True,
|
||||
"request_hour_from":"8",
|
||||
"request_hour_from": "8",
|
||||
"request_hour_to": "12",
|
||||
"holiday_status_id": self.time_off_hour_type.id,
|
||||
}
|
||||
@@ -129,8 +230,6 @@ class TestHrLeaveTimeoffDay(TransactionCase):
|
||||
leave._compute_number_of_days_display()
|
||||
leave.state = "validate" # Simulate the leave being validated
|
||||
|
||||
|
||||
|
||||
self.env["hr.leave.timeoff.day"].cron_manage_timeoff_days()
|
||||
timeoff_days = self.env["hr.leave.timeoff.day"].search(
|
||||
[
|
||||
@@ -150,19 +249,101 @@ class TestHrLeaveTimeoffDay(TransactionCase):
|
||||
)
|
||||
|
||||
def test_leave_duration_by_day_compare_to_time_part_employee_calendar(self):
|
||||
employee_calendar = self.env['resource.calendar'].create({
|
||||
'name': 'Employee Calendar',
|
||||
'attendance_ids': [
|
||||
(0, 0, {'name': 'Monday Morning', 'dayofweek': '0', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Monday Afternoon', 'dayofweek': '0', 'hour_from': 13, 'hour_to': 17, 'day_period': 'afternoon'}),
|
||||
(0, 0, {'name': 'Tuesday Morning', 'dayofweek': '1', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Tuesday Afternoon', 'dayofweek': '1', 'hour_from': 13, 'hour_to': 17, 'day_period': 'afternoon'}),
|
||||
(0, 0, {'name': 'Wednesday Morning', 'dayofweek': '2', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Wednesday Afternoon', 'dayofweek': '2', 'hour_from': 13, 'hour_to': 17, 'day_period': 'afternoon'}),
|
||||
(0, 0, {'name': 'Thursday Morning', 'dayofweek': '3', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Thursday Afternoon', 'dayofweek': '3', 'hour_from': 13, 'hour_to': 17, 'day_period': 'afternoon'}),
|
||||
],
|
||||
})
|
||||
employee_calendar = self.env["resource.calendar"].create(
|
||||
{
|
||||
"name": "Employee Calendar",
|
||||
"attendance_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Monday Morning",
|
||||
"dayofweek": "0",
|
||||
"hour_from": 8,
|
||||
"hour_to": 12,
|
||||
"day_period": "morning",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Monday Afternoon",
|
||||
"dayofweek": "0",
|
||||
"hour_from": 13,
|
||||
"hour_to": 17,
|
||||
"day_period": "afternoon",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Tuesday Morning",
|
||||
"dayofweek": "1",
|
||||
"hour_from": 8,
|
||||
"hour_to": 12,
|
||||
"day_period": "morning",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Tuesday Afternoon",
|
||||
"dayofweek": "1",
|
||||
"hour_from": 13,
|
||||
"hour_to": 17,
|
||||
"day_period": "afternoon",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Wednesday Morning",
|
||||
"dayofweek": "2",
|
||||
"hour_from": 8,
|
||||
"hour_to": 12,
|
||||
"day_period": "morning",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Wednesday Afternoon",
|
||||
"dayofweek": "2",
|
||||
"hour_from": 13,
|
||||
"hour_to": 17,
|
||||
"day_period": "afternoon",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Thursday Morning",
|
||||
"dayofweek": "3",
|
||||
"hour_from": 8,
|
||||
"hour_to": 12,
|
||||
"day_period": "morning",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Thursday Afternoon",
|
||||
"dayofweek": "3",
|
||||
"hour_from": 13,
|
||||
"hour_to": 17,
|
||||
"day_period": "afternoon",
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
)
|
||||
self.employee.resource_calendar_id = employee_calendar
|
||||
|
||||
leave = self.env["hr.leave"].create(
|
||||
@@ -194,7 +375,8 @@ class TestHrLeaveTimeoffDay(TransactionCase):
|
||||
)
|
||||
|
||||
def test_public_holidays_between_a_leave(self):
|
||||
# Leaves the code below commented because default database already has a public holiday on 8th May 2025
|
||||
# Leaves the code below commented because
|
||||
# the default database already has a public holiday on 8th May 2025
|
||||
# self.env["resource.calendar.leaves"].create(
|
||||
# {
|
||||
# "name": "8 mai 2025",
|
||||
@@ -206,7 +388,9 @@ class TestHrLeaveTimeoffDay(TransactionCase):
|
||||
{
|
||||
"employee_id": self.employee.id,
|
||||
"request_date_from": Date.to_date("2025-05-05"),
|
||||
"request_date_to": Date.to_date("2025-05-11"), #a public holiday is in between (8 may)
|
||||
"request_date_to": Date.to_date(
|
||||
"2025-05-11"
|
||||
), # a public holiday is in between (8 may)
|
||||
"holiday_status_id": self.time_off_type.id,
|
||||
}
|
||||
)
|
||||
@@ -267,7 +451,7 @@ class TestHrLeaveTimeoffDay(TransactionCase):
|
||||
self.assertEqual(
|
||||
len(timeoff_days), 0, "There should be no timeoff days for this leave"
|
||||
)
|
||||
|
||||
|
||||
def test_deleted_leave(self):
|
||||
leave = self.env["hr.leave"].create(
|
||||
{
|
||||
@@ -305,4 +489,3 @@ class TestHrLeaveTimeoffDay(TransactionCase):
|
||||
self.assertEqual(
|
||||
len(timeoff_days), 0, "There should be no timeoff days for this leave"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user