[IMP] hr_work_entry: Improve error message to be more user friendly

closes odoo/odoo#94885

X-original-commit: 77c0dc3eb75b568b4e6aab9bc26f6e5b5f0f8d4b
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Yannick Tivisse
2022-07-01 16:35:34 +02:00
parent 4cf496a190
commit 0d4a621e5a
2 changed files with 29 additions and 5 deletions
@@ -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
@@ -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):
"""