fix termination and holiday balance

This commit is contained in:
Bakry 2024-12-22 18:45:48 +03:00
parent 5a5782f9a0
commit 092abfce58
1 changed files with 20 additions and 10 deletions

View File

@ -164,9 +164,9 @@ class HrTermination(models.Model):
cron_run_date = datetime.strptime(str(leave.holiday_ids[-1].cron_run_date), "%Y-%m-%d").date()
date_to_check = (datetime.utcnow() + timedelta(hours=3)).date()
last_working_date = datetime.strptime(str(rec.last_work_date), "%Y-%m-%d").date()
if cron_run_date < date_to_check:
date_to_check = cron_run_date
to_work_days = (last_working_date - date_to_check).days
#if cron_run_date < date_to_check:
# date_to_check = cron_run_date
#to_work_days = (last_working_date - date_to_check).days
first_hiring_date = datetime.strptime(str(leave.hiring_date), "%Y-%m-%d").date()
last_work_date = datetime.strptime(str(rec.last_work_date), "%Y-%m-%d").date()
@ -176,22 +176,32 @@ class HrTermination(models.Model):
if item.date_from <= working_years < item.date_to:
holiday_duration = item.duration
###get last cron date to compute leave_balance_date
to_work_days2 = 0
diff_days = 0
new_balance=0
"""the last working date less than cron run date"""
if cron_run_date < last_working_date:
to_work_days2 = (last_working_date - cron_run_date).days
diff_days = (last_working_date - cron_run_date).days
for i in range(1, diff_days + 1):
cala_date = cron_run_date + timedelta(days=i)
balance_day = leave.remaining_leaves_of_day_by_date(rec.employee_id, str(cala_date),
leave.holiday_status_id , is_month=False, is_years=False)
new_balance = new_balance + balance_day
else:
to_work_days2 = -(cron_run_date - last_working_date).days
upcoming_leave2 = leave.remaining_leaves_of_day_by_date(rec.employee_id, str(date_to_check),\
leave.holiday_status_id , is_month=False, is_years=False) * to_work_days2
diff_days = -(cron_run_date - last_working_date).days
for i in range(1, -diff_days + 1):
cala_date = last_working_date + timedelta(days=i)
balance_day = leave.remaining_leaves_of_day_by_date(rec.employee_id, str(cala_date),
leave.holiday_status_id , is_month=False, is_years=False)
new_balance = new_balance - balance_day
####################### END
#upcoming_leave = ((holiday_duration / 12) / 30.39) * to_work_days
leave_balance = round(rec.employee_id.remaining_leaves + upcoming_leave2, 2)
leave_balance = round(rec.employee_id.remaining_leaves + new_balance, 2)
exceed_days = leave.holiday_status_id.number_of_save_days + holiday_duration
if leave_balance > exceed_days:
rec.leave_balance = exceed_days
else:
rec.leave_balance = round(rec.employee_id.remaining_leaves + upcoming_leave2, 2)
rec.leave_balance = round(rec.employee_id.remaining_leaves + new_balance, 2)
self._compute_holiday_amount()
def current_date_hijri(self):