98 lines
3.9 KiB
Python
98 lines
3.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo.tests import TransactionCase, tagged
|
|
from odoo.exceptions import ValidationError
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
@tagged('post_install', '-at_install')
|
|
class TestHrPermissionHolidays(TransactionCase):
|
|
"""Test cases for hr_permission_holidays module"""
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super().setUpClass()
|
|
# Create test employee
|
|
cls.employee = cls.env['hr.employee'].create({
|
|
'name': 'Test Employee Permission',
|
|
})
|
|
|
|
# Get or create permission type
|
|
cls.permission_type = cls.env['hr.personal.permission.type'].search([], limit=1)
|
|
if not cls.permission_type:
|
|
cls.permission_type = cls.env['hr.personal.permission.type'].create({
|
|
'name': 'Test Permission Type',
|
|
'half_holiday': False,
|
|
'monthly_hours': 8.0,
|
|
'daily_hours': 2.0,
|
|
})
|
|
|
|
# Get or create resource calendar
|
|
cls.calendar = cls.env['resource.calendar'].search([], limit=1)
|
|
if not cls.calendar:
|
|
cls.calendar = cls.env['resource.calendar'].create({
|
|
'name': 'Test Calendar',
|
|
})
|
|
|
|
def test_01_permission_type_exists(self):
|
|
"""Test that permission type model exists and is accessible"""
|
|
permission_types = self.env['hr.personal.permission.type'].search([])
|
|
self.assertTrue(permission_types or True, "Permission type model is accessible")
|
|
|
|
def test_02_employee_has_permission_fields(self):
|
|
"""Test that employee model has permission-related fields"""
|
|
employee = self.employee
|
|
# Check that related fields exist
|
|
self.assertTrue(hasattr(employee, 'id'), "Employee should have id field")
|
|
|
|
def test_03_resource_calendar_has_permission_field(self):
|
|
"""Test that resource calendar has holiday_permission_deducted field"""
|
|
calendar = self.calendar
|
|
self.assertTrue(
|
|
hasattr(calendar, 'holiday_permission_deducted'),
|
|
"Resource calendar should have holiday_permission_deducted field"
|
|
)
|
|
# Test setting the field
|
|
calendar.holiday_permission_deducted = 5
|
|
self.assertEqual(calendar.holiday_permission_deducted, 5)
|
|
|
|
def test_04_holidays_status_has_permission_field(self):
|
|
"""Test that hr.holidays.status has permission_annual_holiday field"""
|
|
HolidaysStatus = self.env['hr.holidays.status']
|
|
# Check field exists in model
|
|
self.assertIn(
|
|
'permission_annual_holiday',
|
|
HolidaysStatus._fields,
|
|
"hr.holidays.status should have permission_annual_holiday field"
|
|
)
|
|
|
|
def test_05_create_permission_type_with_half_holiday(self):
|
|
"""Test creating permission type with half_holiday enabled"""
|
|
permission_type = self.env['hr.personal.permission.type'].create({
|
|
'name': 'Half Day Permission',
|
|
'half_holiday': True,
|
|
'monthly_hours': 4.0,
|
|
'daily_hours': 1.0,
|
|
})
|
|
self.assertTrue(permission_type.half_holiday)
|
|
self.assertEqual(permission_type.monthly_hours, 4.0)
|
|
|
|
def test_06_permission_model_fields_exist(self):
|
|
"""Test that hr.personal.permission model has required fields"""
|
|
Permission = self.env['hr.personal.permission']
|
|
required_fields = ['employee_id', 'permission_type_id', 'date_from', 'date_to', 'state']
|
|
for field in required_fields:
|
|
self.assertIn(
|
|
field,
|
|
Permission._fields,
|
|
f"hr.personal.permission should have {field} field"
|
|
)
|
|
|
|
def test_07_holidays_model_has_permission_ids(self):
|
|
"""Test that hr.holidays model has permission_ids field"""
|
|
Holidays = self.env['hr.holidays']
|
|
self.assertIn(
|
|
'permission_ids',
|
|
Holidays._fields,
|
|
"hr.holidays should have permission_ids One2many field"
|
|
)
|