diff --git a/addons/hr_holidays/i18n/hr_holidays.pot b/addons/hr_holidays/i18n/hr_holidays.pot index 3c743b36c66..f11266a6272 100644 --- a/addons/hr_holidays/i18n/hr_holidays.pot +++ b/addons/hr_holidays/i18n/hr_holidays.pot @@ -4132,6 +4132,12 @@ msgstr "" msgid "You cannot delete an allocation request which is in %s state." msgstr "" +#. module: hr_holidays +#: code:addons/hr_holidays/models/hr_leave_allocation.py:0 +#, python-format +msgid "You cannot delete an allocation request which has some validated leaves." +msgstr "" + #. module: hr_holidays #: code:addons/hr_holidays/models/hr_leave.py:0 #, python-format diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index 51404fdb5d3..42c639f54b0 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -583,6 +583,11 @@ class HolidaysAllocation(models.Model): for holiday in self.filtered(lambda holiday: holiday.state not in ['draft', 'cancel', 'confirm']): raise UserError(_('You cannot delete an allocation request which is in %s state.') % (state_description_values.get(holiday.state),)) + @api.ondelete(at_uninstall=False) + def _unlink_if_no_leaves(self): + if any(allocation.holiday_status_id.requires_allocation == 'yes' and allocation.leaves_taken > 0 for allocation in self): + raise UserError(_('You cannot delete an allocation request which has some validated leaves.')) + def _get_mail_redirect_suggested_company(self): return self.holiday_status_id.company_id