Skip to content
Snippets Groups Projects
Commit 3f5e3b05 authored by Yannick Tivisse's avatar Yannick Tivisse
Browse files

[FIX] hr_work_entry_holidays: Allow overlapping leaves if same schedule

Purpose
=======

We currently prevent leaves overlapping several contracts to avoid messing
with the generated resource.calendar.leave.

In case the contracts are on the same resource calendar, this shouldn't be
an issue actually.

Taskid: 2836901
X-original-commit: 4e87c30bb136083153091e67e6dd9d9f64fa94c2
Part-of: odoo/odoo#94885
parent 68bb3838
Branches
Tags
No related merge requests found
......@@ -24,7 +24,7 @@ msgstr ""
#. module: hr_work_entry_holidays
#: code:addons/hr_work_entry_holidays/models/hr_leave.py:0
#, python-format
msgid "A leave cannot be set across multiple contracts."
msgid "A leave cannot be set across multiple contracts with different working schedules."
msgstr ""
#. module: hr_work_entry_holidays
......
......@@ -69,11 +69,11 @@ class HrLeave(models.Model):
('date_end', '=', False),
('state', '!=', 'close')
]
nbr_contracts = self.env['hr.contract'].sudo().search_count(domain)
if nbr_contracts > 1:
contracts = self.env['hr.contract'].sudo().search(domain)
if len(contracts.resource_calendar_id) > 1:
contracts = self.env['hr.contract'].sudo().search(domain)
raise ValidationError(
_('A leave cannot be set across multiple contracts.') + '\n%s\n%s' % (
_('A leave cannot be set across multiple contracts with different working schedules.') + '\n%s\n%s' % (
', '.join(contracts.mapped('name')),
holiday.display_name))
......
# # -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import datetime
from datetime import datetime, date
from odoo.exceptions import ValidationError
from odoo.tests import tagged
from odoo.addons.hr_work_entry_holidays.tests.common import TestWorkEntryHolidaysBase
@tagged('work_entry_multi_contract')
class TestWorkEntryHolidaysMultiContract(TestWorkEntryHolidaysBase):
@classmethod
......@@ -118,3 +120,21 @@ class TestWorkEntryHolidaysMultiContract(TestWorkEntryHolidaysBase):
leave._compute_number_of_hours_display()
self.assertEqual(leave.number_of_hours_display, 14, "It should count hours according to the future contract.")
def test_leave_multi_contracts_same_schedule(self):
# Allow leaves overlapping multiple contracts if same
# resource calendar
leave = self.create_leave(datetime(2022, 6, 1, 7, 0, 0), datetime(2022, 6, 30, 18, 0, 0))
leave.action_approve()
self.contract_cdi.date_end = date(2022, 6, 15)
new_contract_cdi = self.env['hr.contract'].create({
'date_start': date(2022, 6, 16),
'name': 'New Contract for Jules',
'resource_calendar_id': self.calendar_35h.id,
'wage': 5000.0,
'employee_id': self.jules_emp.id,
'state': 'draft',
'kanban_state': 'normal',
})
new_contract_cdi.state = 'open'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment