fix balance take with year balance and refuse

This commit is contained in:
Bakry 2025-09-02 14:52:13 +03:00
parent 4b1398b71c
commit 00c8630189
1 changed files with 41 additions and 4 deletions

View File

@ -1229,8 +1229,8 @@ class HRHolidays(models.Model):
next_years = date_from.replace(year=date_from.year + 1)
number_of_years = relativedelta.relativedelta(current_date, date_from).years
if number_of_years >= 1:
self._create_inverse_holiday(already_exist, next_years)
remaining_leaves = self._calculate_remaining_leaves(emp , item, next_years)
self._create_inverse_holiday(already_exist, next_years,remaining_leaves)
already_exist.write({
'name': f'Yearly Allocation of {item.name} Leaves',
'remaining_leaves': remaining_leaves,
@ -1259,10 +1259,12 @@ class HRHolidays(models.Model):
]
return self.env['hr.holidays'].search(domain, order="date_from desc")
def _create_inverse_holiday(self, already_exist, next_years):
def _create_inverse_holiday(self, already_exist, next_years,balance):
self.env['hr.inverse.holidays'].create({
'holiday_id': already_exist.id,
'cron_run_date': next_years,
'balance_leaves': balance,
})
def _calculate_remaining_leaves(self, emp,item, next_years):
@ -1460,8 +1462,26 @@ class HRHolidays(models.Model):
order='id desc', limit=1)
if employee_balance:
if item.type == 'remove' and item.request_done==False:
holiday_days = item.number_of_days_temp
"""Take a holiday balance with an old year balance"""
leave_type = ['exam', 'marriage','parental','emergency','sick']
if item.holiday_status_id.leave_type in leave_type:
cron_run_date = item.employee_id.first_hiring_date
date_from = fields.Date.from_string(item.date_from)
holi_date_from = fields.Date.from_string(item.date_from)
holi_date_to = fields.Date.from_string(item.date_to)
if employee_balance.holiday_ids:
cron_run_date = employee_balance.holiday_ids[-1].cron_run_date
if cron_run_date > holi_date_to:
holiday_days = 0
if holi_date_to >= cron_run_date > holi_date_from:
holiday_days = (holi_date_to - cron_run_date).days+1
employee_balance.write({
'remaining_leaves': employee_balance.remaining_leaves - item.number_of_days_temp,
'remaining_leaves': employee_balance.remaining_leaves - holiday_days,
'leaves_taken': employee_balance.leaves_taken + item.number_of_days_temp,
})
if item.issuing_ticket == 'yes':
@ -1626,8 +1646,25 @@ class HRHolidays(models.Model):
allocation = self.env['hr.holidays'].search(domain, order='id desc', limit=1)
if balance:
if holiday.type == 'remove':
holiday_days = holiday.number_of_days_temp
"""return a holiday take balance with an old year balance"""
leave_type = ['exam', 'marriage','parental','emergency','sick']
if holiday.holiday_status_id.leave_type in leave_type:
cron_run_date = holiday.employee_id.first_hiring_date
date_from = fields.Date.from_string(holiday.date_from)
holi_date_from = fields.Date.from_string(holiday.date_from)
holi_date_to = fields.Date.from_string(holiday.date_to)
if balance.holiday_ids:
cron_run_date = balance.holiday_ids[-1].cron_run_date
if cron_run_date > holi_date_to:
holiday_days = 0
if holi_date_to >= cron_run_date > holi_date_from:
holiday_days = (holi_date_to - cron_run_date).days+1
balance.write({
'remaining_leaves': balance.remaining_leaves + holiday.number_of_days_temp,
'remaining_leaves': balance.remaining_leaves + holiday_days,
'leaves_taken': balance.leaves_taken - holiday.number_of_days_temp,
})
[self.env[model].search([('employee_id', '=', holiday.employee_id.id),