Merge pull request #287 from expsa/abuzar_fix_hr

fix bug
This commit is contained in:
AbuzarExp 2024-07-20 13:44:27 +03:00 committed by GitHub
commit 949a97ee56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 50 additions and 11 deletions

View File

@ -112,18 +112,20 @@ class HrPersonalPermission(models.Model):
@api.onchange('date_to', 'date_from', 'employee_id')
def permission_number_decrement(self):
for item in self:
# item._onchange_time()
# item._onchange_time()
if item.employee_id:
if not item.employee_id.first_hiring_date:
raise exceptions.Warning(
_('You can not Request Permission The Employee have Not First Hiring Date'))
if item.date_to:
current_date = datetime.strptime(str(item.date_to), DEFAULT_SERVER_DATETIME_FORMAT)
current_month = datetime.strptime(str(item.date_to), DEFAULT_SERVER_DATETIME_FORMAT).month
date_from = current_date.strftime('%Y-{0}-01'.format(current_month))
date_to = current_date.strftime('%Y-{0}-01'.format(current_month + 1))
current_month = current_date.month
date_from = current_date.strftime('%Y-%m-01')
if current_month == 12:
date_to = current_date.strftime('%Y-{0}-31'.format(current_month))
date_to = current_date.strftime('%Y-12-31')
else:
date_to = (current_date.replace(month=current_month + 1, day=1) - timedelta(days=1)).strftime('%Y-%m-%d')
number_of_per = item.employee_id.contract_id.working_hours.permission_number
employee_permissions = self.search([
('employee_id', '=', item.employee_id.id),
@ -136,21 +138,58 @@ class HrPersonalPermission(models.Model):
all_perission += rec.duration
if rec.date_to and item.date_to:
permission_date1 = datetime.strptime(rec.date_to,
DEFAULT_SERVER_DATETIME_FORMAT).date()
date_to_value1 = datetime.strptime(item.date_to, DEFAULT_SERVER_DATETIME_FORMAT).date()
permission_date1 = rec.date_to.date() if isinstance(rec.date_to, datetime) else datetime.strptime(rec.date_to, DEFAULT_SERVER_DATETIME_FORMAT).date()
date_to_value1 = item.date_to.date() if isinstance(item.date_to, datetime) else datetime.strptime(item.date_to, DEFAULT_SERVER_DATETIME_FORMAT).date()
if permission_date1 == date_to_value1:
raise exceptions.Warning(
_('Sorry You Have Used All Your Permission In This Day you have one permission per a Day'))
if number_of_per > all_perission:
item.permission_number = round(number_of_per - all_perission, 2)
else:
raise ValidationError(_('Sorry You Have Used All Your Permission Hours In This Month'))
# def permission_number_decrement(self):
# for item in self:
# # item._onchange_time()
# if item.employee_id:
# if not item.employee_id.first_hiring_date:
# raise exceptions.Warning(
# _('You can not Request Permission The Employee have Not First Hiring Date'))
# if item.date_to:
# current_date = datetime.strptime(str(item.date_to), DEFAULT_SERVER_DATETIME_FORMAT)
# current_month = datetime.strptime(str(item.date_to), DEFAULT_SERVER_DATETIME_FORMAT).month
# date_from = current_date.strftime('%Y-{0}-01'.format(current_month))
# date_to = current_date.strftime('%Y-{0}-01'.format(current_month + 1))
# if current_month == 12:
# date_to = current_date.strftime('%Y-{0}-31'.format(current_month))
# number_of_per = item.employee_id.contract_id.working_hours.permission_number
# employee_permissions = self.search([
# ('employee_id', '=', item.employee_id.id),
# ('state', '=', 'approve'),
# ('date_from', '>=', date_from),
# ('date_to', '<=', date_to)])
# all_perission = 0
# for rec in employee_permissions:
# all_perission += rec.duration
# if rec.date_to and item.date_to:
# permission_date1 = datetime.strptime(rec.date_to,
# DEFAULT_SERVER_DATETIME_FORMAT).date()
# date_to_value1 = datetime.strptime(item.date_to, DEFAULT_SERVER_DATETIME_FORMAT).date()
# if permission_date1 == date_to_value1:
# raise exceptions.Warning(
# _('Sorry You Have Used All Your Permission In This Day you have one permission per a Day'))
# if number_of_per > all_perission:
# item.permission_number = round(number_of_per - all_perission, 2)
# else:
# raise ValidationError(_('Sorry You Have Used All Your Permission Hours In This Month'))
def check_holiday_mission(self):
for rec in self: