diff --git a/odex25_hr/hr_holidays_public/models/hr_holidays.py b/odex25_hr/hr_holidays_public/models/hr_holidays.py index fba4d971d..2dd06cf27 100644 --- a/odex25_hr/hr_holidays_public/models/hr_holidays.py +++ b/odex25_hr/hr_holidays_public/models/hr_holidays.py @@ -1462,24 +1462,7 @@ 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 - - + holiday_days = item._chick_year_leavs_balance() employee_balance.write({ 'remaining_leaves': employee_balance.remaining_leaves - holiday_days, 'leaves_taken': employee_balance.leaves_taken + item.number_of_days_temp, @@ -1635,6 +1618,30 @@ class HRHolidays(models.Model): self.remove_delegated_access() self.write({'state': 'cancel'}) + def _chick_year_leavs_balance(self): + """chick a holiday take balance with years balance""" + for item in self: + holiday_days = item.number_of_days_temp + employee_balance = self.env['hr.holidays'].search([('employee_id', '=', item.employee_id.id), + ('holiday_status_id', '=', item.holiday_status_id.id), + ('type', '=', 'add'), + ('check_allocation_view', '=', 'balance')], + order='id desc', limit=1) + 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 + 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 + + return holiday_days + def reconcile_holiday_balance(self): for holiday in self: domain = [('check_allocation_view', '=', 'balance'), @@ -1646,23 +1653,7 @@ 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 - + holiday_days = holiday._chick_year_leavs_balance() balance.write({ 'remaining_leaves': balance.remaining_leaves + holiday_days, 'leaves_taken': balance.leaves_taken - holiday.number_of_days_temp,