fix holiday

This commit is contained in:
Bakry 2025-12-23 12:52:57 +03:00
parent 9eefc082cd
commit e05a9dd62c
1 changed files with 12 additions and 10 deletions

View File

@ -487,20 +487,22 @@ class HRHolidays(models.Model):
last_date = datetime.strftime(today, "{0}-12-31".format(years))
last_date = datetime.strptime(str(last_date), "%Y-%m-%d").date()
start_days = last_date - timedelta(days=int(holiday.remained_before))
if today < last_date:
balance = self.env['hr.holidays'].search([('employee_id', '=', emp.id),
if start_days <= today < last_date:
if today.weekday() != 6: # Send on Sunday only, not every day
return
balance = self.env['hr.holidays'].search([('employee_id', '=', emp.id),
('holiday_status_id', '=', holiday.id),
('type', '=', 'add'),
('check_allocation_view', '=', 'balance')
], limit=1, order="id desc")
holi_balance = balance.remaining_leaves or 0.0
if today >= start_days < last_date:
if holi_balance > holiday.number_of_save_days:
if emp.user_id:
template = self.env.ref('hr_holidays_public.email_template_holiday_balance', False)
template.write({'email_to': emp.user_id.partner_id.email, 'lang': emp.user_id.lang,
'email_cc': '%s' % (self.env.user.company_id.hr_email)})
template.send_mail(balance.id)
holi_balance = balance.remaining_leaves or 0.0
if holi_balance > holiday.number_of_save_days:
if emp.user_id:
template = self.env.ref('hr_holidays_public.email_template_holiday_balance', False)
template.write({'email_to': emp.user_id.partner_id.email, 'lang': emp.user_id.lang,
'email_cc': '%s' % (self.env.user.company_id.hr_email)})
template.send_mail(balance.id)
if holiday.payslip_type == 'unpaid':
tomorrow = (fields.Datetime.from_string(fields.Datetime.now()) + timedelta(days=1)).strftime(
'%Y-%m-%d 00:00:00')