[IMP]hr_negative_leave:add tests
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m29s

This commit is contained in:
2025-11-07 10:33:15 +01:00
parent ee1e1cbe65
commit 726e34febc
3 changed files with 98 additions and 19 deletions

View File

@@ -15,27 +15,11 @@ class HolidaysType(models.Model):
allows_negative = fields.Boolean(string='Allow Negative Leaves',
help="If checked, users request can exceed the allocated days and balance can go in negative.")
remaining_leaves_allowing_negative = fields.Float(
string="Remaining Leaves when Negative Allowed",
compute='_compute_remaining_leaves_allowing_negative',
)
def _compute_remaining_leaves_allowing_negative(self):
for holiday_type in self:
if holiday_type.allows_negative:
# if left != usable : remaining_leaves_allowing_negative = left + usable
if holiday_type.virtual_remaining_leaves < 0 (holiday_type.max_leaves - holiday_type.virtual_leaves_taken) != holiday_type.virtual_remaining_leaves:
holiday_type.remaining_leaves_allowing_negative = holiday_type.max_leaves - holiday_type.virtual_leaves_taken + holiday_type.virtual_remaining_leaves
else:
# else : remaining_leaves_allowing_negative = left as usual
holiday_type.remaining_leaves_allowing_negative = holiday_type.max_leaves - holiday_type.virtual_leaves_taken
else:
holiday_type.remaining_leaves_allowing_negative = None
@api.depends('requires_allocation')
def _compute_valid(self):
res = super()._compute_valid()
for holiday_type in res:
#if negative is allowed, then the holiday type is valid in any case
if not holiday_type.has_valid_allocation:
holiday_type.has_valid_allocation = holiday_type.allows_negative
@@ -155,9 +139,9 @@ class HolidaysType(models.Model):
continue
# calculate the number of days/hours for this allocation (allocation days/hours - leaves already taken)
virtual_remaining_leaves = (available_allocation.number_of_days if leave_unit == 'days' else available_allocation.number_of_hours_display) - allocations_days_consumed[employee_id][holiday_status_id][available_allocation]['virtual_leaves_taken']
###########################################
#############################################
# Modification for leaves allowing negative #
###########################################
#############################################
# if negative is allowed for this leave type, we can exceed the number of available days in this allocation
if holiday_status_id.allows_negative:
max_leaves = leave_duration
@@ -165,6 +149,9 @@ class HolidaysType(models.Model):
# if negative is not allowed for this leave type, then we cannot exceed the allocation amount
# the max leaves for this allocation is the minimum between the remaining available days and the leave duration
max_leaves = min(virtual_remaining_leaves, leave_duration)
####################################################
# END OF Modification for leaves allowing negative #
####################################################
# the new calculation of days taken for this allocation is previous taken + max_leaves (which can never exceed the allocation total)
days_consumed[available_allocation]['virtual_leaves_taken'] += max_leaves
if leave.state == 'validate':