[FIX] hr_holidays: prevent deletion of allocation with taken leaves

In case we try to delete an allocation, we should add a check if there
are already taken leaves, otherwise it could lead to an incoherent
situation with validated leaves without allocation while their
associated time off type is requiring allocation.

closes odoo/odoo#90932

X-original-commit: 45567dddacae82f9b4e985703cbb9e7736e9beb0
Signed-off-by: Kevin Baptiste <kba@odoo.com>
Signed-off-by: Alex Thuyls (alt) <alt@odoo.com>
This commit is contained in:
alt-odoo
2022-05-09 19:56:56 +02:00
parent 4bf43e21de
commit c962fe4e19
2 changed files with 11 additions and 0 deletions
+6
View File
@@ -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
@@ -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