Merge branch 'dev_odex25_hr' of https://github.com/expsa/odex25-standard-modules into bakry_edit
# Conflicts: # odex25_hr/employee_requests/views/hr_personal_permission.xml
This commit is contained in:
commit
05a232caa8
|
|
@ -36,34 +36,34 @@ class HrPersonalPermission(models.Model):
|
|||
state = fields.Selection([('draft', _('Draft')), ('send', _('Waiting Direct Manager')), ('direct_manager', _('Wait HR Department')),('approve', _('Approved')), ('refused', _('Refused'))], default="draft", tracking=True)
|
||||
type_exit = fields.Selection([('early_exit', _('Early Exit')), ('late entry', _('Late Entry')), ('during work', _('During Work'))],default="early_exit")
|
||||
company_id = fields.Many2one('res.company',string="Company", default=lambda self: self.env.user.company_id)
|
||||
time_permission_from = fields.Float(string="Permission From (24h format)", help="Time in 24-hour format (e.g., 13.5 for 1:30 PM)")
|
||||
time_permission_to = fields.Float(string="Permission To (24h format)", help="Time in 24-hour format (e.g., 15.75 for 3:45 PM)")
|
||||
# time_permission_from = fields.Float(string="Permission From (24h format)", help="Time in 24-hour format (e.g., 13.5 for 1:30 PM)")
|
||||
# time_permission_to = fields.Float(string="Permission To (24h format)", help="Time in 24-hour format (e.g., 15.75 for 3:45 PM)")
|
||||
|
||||
|
||||
@api.onchange('time_permission_from', 'time_permission_to', 'date')
|
||||
def _onchange_time(self):
|
||||
for record in self:
|
||||
if (not record.time_permission_from < record.time_permission_to):
|
||||
record.time_permission_to = record.time_permission_from + 0.5
|
||||
record.time_permission_from = record.time_permission_from
|
||||
if record.date:
|
||||
date_from = self._combine_date_and_time(record.date, record.time_permission_from)
|
||||
record.date_from = date_from
|
||||
# @api.onchange('time_permission_from', 'time_permission_to', 'date')
|
||||
# def _onchange_time(self):
|
||||
# for record in self:
|
||||
# if (not record.time_permission_from < record.time_permission_to):
|
||||
# record.time_permission_to = record.time_permission_from + 0.5
|
||||
# record.time_permission_from = record.time_permission_from
|
||||
# if record.date:
|
||||
# date_from = self._combine_date_and_time(record.date, record.time_permission_from)
|
||||
# record.date_from = date_from
|
||||
|
||||
if record.date:
|
||||
date_to = self._combine_date_and_time(record.date, record.time_permission_to)
|
||||
record.date_to = date_to
|
||||
# if record.date:
|
||||
# date_to = self._combine_date_and_time(record.date, record.time_permission_to)
|
||||
# record.date_to = date_to
|
||||
|
||||
def _combine_date_and_time(self, date, time_float):
|
||||
""" Combine a date and a float time (e.g. 13.5) into a datetime object. """
|
||||
hours = int(time_float)
|
||||
minutes = int((time_float - hours) * 60)
|
||||
import pytz
|
||||
date_time = datetime.combine(date, datetime.min.time()) + timedelta(hours=hours, minutes=minutes)
|
||||
# if time_float > 0:
|
||||
date_time = fields.Datetime.to_string(pytz.timezone(self.env.context['tz']).localize(fields.Datetime.from_string(date_time), is_dst=None).astimezone(pytz.utc))
|
||||
# date_time = fields.Datetime.to_string(pytz.timezone(self.env.context['tz']).localize(fields.Datetime.from_string(date_time), is_dst=None).astimezone(pytz.utc) + timedelta(hours=24))
|
||||
return date_time
|
||||
# def _combine_date_and_time(self, date, time_float):
|
||||
# """ Combine a date and a float time (e.g. 13.5) into a datetime object. """
|
||||
# hours = int(time_float)
|
||||
# minutes = int((time_float - hours) * 60)
|
||||
# import pytz
|
||||
# date_time = datetime.combine(date, datetime.min.time()) + timedelta(hours=hours, minutes=minutes)
|
||||
# # if time_float > 0:
|
||||
# date_time = fields.Datetime.to_string(pytz.timezone(self.env.context['tz']).localize(fields.Datetime.from_string(date_time), is_dst=None).astimezone(pytz.utc))
|
||||
# # date_time = fields.Datetime.to_string(pytz.timezone(self.env.context['tz']).localize(fields.Datetime.from_string(date_time), is_dst=None).astimezone(pytz.utc) + timedelta(hours=24))
|
||||
# return date_time
|
||||
|
||||
|
||||
@api.model
|
||||
|
|
@ -97,7 +97,7 @@ class HrPersonalPermission(models.Model):
|
|||
@api.depends('date_from', 'date_to')
|
||||
def get_duration_no(self):
|
||||
for item in self:
|
||||
item._onchange_time()
|
||||
# item._onchange_time()
|
||||
if item.date_from and item.date_to:
|
||||
start_date_value = datetime.strptime(str(item.date_from), "%Y-%m-%d %H:%M:%S")
|
||||
end_date = datetime.strptime(str(item.date_to), "%Y-%m-%d %H:%M:%S")
|
||||
|
|
@ -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:
|
||||
|
|
@ -258,15 +297,15 @@ class HrPersonalPermission(models.Model):
|
|||
if item.duration > item.permission_number:
|
||||
raise exceptions.Warning(
|
||||
_('This Duration not Allowed it must be Less Than or equal Permission Hours in Month'))
|
||||
for employee_permission in employee_permissions:
|
||||
if employee_permission.date_to and item.date_to:
|
||||
permission_date = datetime.strptime(str(employee_permission.date_to),
|
||||
DEFAULT_SERVER_DATETIME_FORMAT).date()
|
||||
date_to_value = datetime.strptime(str(item.date_to), DEFAULT_SERVER_DATETIME_FORMAT).date()
|
||||
|
||||
if employee_permissions.date_to and item.date_to:
|
||||
permission_date = datetime.strptime(str(employee_permissions.date_to),
|
||||
DEFAULT_SERVER_DATETIME_FORMAT).date()
|
||||
date_to_value = datetime.strptime(str(item.date_to), DEFAULT_SERVER_DATETIME_FORMAT).date()
|
||||
|
||||
if permission_date == date_to_value:
|
||||
raise exceptions.Warning(
|
||||
_('Sorry You Have Used All Your Permission In This Day you have one permission per a Day'))
|
||||
if permission_date == date_to_value:
|
||||
raise exceptions.Warning(
|
||||
_('Sorry You Have Used All Your Permission In This Day you have one permission per a Day'))
|
||||
else:
|
||||
raise exceptions.Warning(_('End Date must be greater than Start Date'))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue