diff --git a/addons/hr_work_entry_holidays/i18n/hr_work_entry_holidays.pot b/addons/hr_work_entry_holidays/i18n/hr_work_entry_holidays.pot index f93a2313598..17a46d783ba 100644 --- a/addons/hr_work_entry_holidays/i18n/hr_work_entry_holidays.pot +++ b/addons/hr_work_entry_holidays/i18n/hr_work_entry_holidays.pot @@ -24,7 +24,16 @@ 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 with different working schedules." +msgid "" +"A leave cannot be set across multiple contracts with different working schedules.\n" +"\n" +"Please create one time off for each contract.\n" +"\n" +"Time off:\n" +"%s\n" +"\n" +"Contracts:\n" +"%s" msgstr "" #. module: hr_work_entry_holidays diff --git a/addons/hr_work_entry_holidays/models/hr_leave.py b/addons/hr_work_entry_holidays/models/hr_leave.py index 6ae03fe6ce8..39e562d57f7 100644 --- a/addons/hr_work_entry_holidays/models/hr_leave.py +++ b/addons/hr_work_entry_holidays/models/hr_leave.py @@ -7,7 +7,7 @@ from datetime import datetime, date from odoo import api, fields, models, _ from odoo.exceptions import ValidationError from odoo.osv.expression import AND - +from odoo.tools import format_date class HrLeaveType(models.Model): _inherit = 'hr.leave.type' @@ -79,10 +79,25 @@ class HrLeave(models.Model): for holiday in self.filtered('employee_id'): contracts = holiday._get_overlapping_contracts() if len(contracts.resource_calendar_id) > 1: + state_labels = {e[0]: e[1] for e in contracts._fields['state']._description_selection(self.env)} raise ValidationError( - _('A leave cannot be set across multiple contracts with different working schedules.') + '\n%s\n%s' % ( - ', '.join(contracts.mapped('name')), - holiday.display_name)) + _("""A leave cannot be set across multiple contracts with different working schedules. + +Please create one time off for each contract. + +Time off: +%s + +Contracts: +%s""", + holiday.display_name, + '\n'.join(_( + "Contract %s from %s to %s, status: %s", + contract.name, + format_date(self.env, contract.date_start), + format_date(self.env, contract.date_start) if contract.date_end else _("undefined"), + state_labels[contract.state] + ) for contract in contracts))) def _cancel_work_entry_conflict(self): """