diff --git a/addons/hr_holidays/tests/__init__.py b/addons/hr_holidays/tests/__init__.py index 8a8765d5b0d..45387174c56 100644 --- a/addons/hr_holidays/tests/__init__.py +++ b/addons/hr_holidays/tests/__init__.py @@ -21,3 +21,4 @@ from . import test_holidays_calendar from . import test_negative from . import test_past_accruals from . import test_allocations +from . import test_multicompany diff --git a/addons/hr_holidays/tests/test_multicompany.py b/addons/hr_holidays/tests/test_multicompany.py new file mode 100644 index 00000000000..cacbc40da48 --- /dev/null +++ b/addons/hr_holidays/tests/test_multicompany.py @@ -0,0 +1,41 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from datetime import date, datetime + +from odoo import tests +from odoo.addons.hr_holidays.tests.common import TestHrHolidaysCommon + + +@tests.tagged('post_install', '-at_install') +class TestHrHolidaysAccessRightsCommon(TestHrHolidaysCommon): + + @classmethod + def setUpClass(cls): + super(TestHrHolidaysAccessRightsCommon, cls).setUpClass() + cls.company_2 = cls.env['res.company'].create({'name': 'Test company 2'}) + + def test_unrelated_public_leave(self): + public_leave = self.env['resource.calendar.leaves'].create({ + 'name': 'Global Time Off for Company 2', + 'resource_id': False, + 'date_from': datetime(2024, 1, 3, 6, 0, 0), + 'date_to': datetime(2024, 1, 3, 19, 0, 0), + }) + public_leave.company_id = self.company_2 + leave_type = self.env['hr.leave.type'].create({ + 'name': 'Test Leave Type', + 'requires_allocation': 'no', + 'request_unit': 'day', + 'company_id': False, + }) + leave = self.env['hr.leave'].create({ + 'name': '3 days leave', + 'employee_id': self.employee_emp_id, + 'holiday_status_id': leave_type.id, + 'request_date_from': date(2024, 1, 2), + 'request_date_to': datetime(2024, 1, 4), + }) + self.assertNotEqual(public_leave.company_id, self.employee_emp.company_id) + self.assertEqual( + leave.number_of_days, 3, + "The leave should not depend on other companies public leaves.")