Merge pull request #1701 from expsa/samir-aladawi-mobile-permission-type
[UPD] odex_mobile: add feature permission type
This commit is contained in:
commit
38c18d85ee
|
|
@ -39,6 +39,7 @@ class PermissionController(http.Controller):
|
|||
"You Have issue in your employee profile. please check with one of your team admins"), success=False)
|
||||
try:
|
||||
permissions = False
|
||||
permission_types = http.request.env['hr.personal.permission.type'].search_read([], ['name'])
|
||||
count = 0
|
||||
emp = []
|
||||
if approvel:
|
||||
|
|
@ -52,6 +53,8 @@ class PermissionController(http.Controller):
|
|||
if permissions:
|
||||
for per in permissions:
|
||||
value = {
|
||||
"permission_type_id": per.permission_type_id.id,
|
||||
"permission_type_name": per.permission_type_id.name,
|
||||
"employee_id": per.employee_id.id,
|
||||
"employee_name": per.employee_id.name,
|
||||
"id": per.id,
|
||||
|
|
@ -71,7 +74,7 @@ class PermissionController(http.Controller):
|
|||
url = "/rest_api/v2/permissions?approvel=%s&page=%s" % (approvel, next) if next else False
|
||||
prev_url = "/rest_api/v2/permissions?approvel=%s&page=%s" % (approvel, prev) if prev else False
|
||||
data = {'links': {'prev': prev_url, 'next': url, }, 'count': count,
|
||||
'results': {'permissions': emp, 'groups': ['group_division_manager', 'group_hr_user']}}
|
||||
'results': {'permission_types': permission_types, 'permissions': emp, 'groups': ['group_division_manager', 'group_hr_user']}}
|
||||
return http_helper.response(message="Data Found", data=data)
|
||||
except (UserError, AccessError, ValidationError, Exception, Warning) as e:
|
||||
http.request._cr.rollback()
|
||||
|
|
@ -95,7 +98,7 @@ class PermissionController(http.Controller):
|
|||
message=_(
|
||||
"You are not allowed to perform this operation. please check with one of your team admins"),
|
||||
success=False)
|
||||
if not body.get('date') or not body.get('date_from') or not body.get('date_to'):
|
||||
if not body.get('date') or not body.get('date_from') or not body.get('date_to') or not body.get('permission_type_id'):
|
||||
return http_helper.response(code=400, message=_("Enter All required Dates for Permission request"),
|
||||
success=False)
|
||||
if not body.get('early_exit'):
|
||||
|
|
@ -108,12 +111,14 @@ class PermissionController(http.Controller):
|
|||
message=_(
|
||||
"You Have issue in your employee profile. please check with one of your team admins"),
|
||||
success=False)
|
||||
permission_type_id = http.request.env['hr.personal.permission.type'].browse(int(body.get('permission_type_id')))
|
||||
permission = None
|
||||
try:
|
||||
permission_number = self.permission_number_decrement(employee, body['date_from'], body['date_to'])
|
||||
permission_number = self.permission_number_decrement(employee, body['date_from'], body['date_to'], permission_type_id)
|
||||
with request.env.cr.savepoint():
|
||||
permission = http.request.env["hr.personal.permission"].sudo().create(
|
||||
{
|
||||
"permission_type_id": permission_type_id.id,
|
||||
"employee_id": employee.id,
|
||||
"date_from": body["date_from"],
|
||||
"date_to": body["date_to"],
|
||||
|
|
@ -140,6 +145,8 @@ class PermissionController(http.Controller):
|
|||
data = {
|
||||
"id": permission.id,
|
||||
"date": str(permission.date),
|
||||
"permission_type_id": permission.permission_type_id.id,
|
||||
"permission_type_name": permission.permission_type_id.name,
|
||||
"duration": permission.duration,
|
||||
"date_from": str(permission.date_from),
|
||||
"date_to": str(permission.date_to),
|
||||
|
|
@ -174,7 +181,7 @@ class PermissionController(http.Controller):
|
|||
message=_(
|
||||
"You are not allowed to perform this operation. please check with one of your team admins"),
|
||||
success=False)
|
||||
if not body.get('date') or not body.get('date_from') or not body.get('date_to'):
|
||||
if not body.get('date') or not body.get('date_from') or not body.get('date_to') or not body.get('permission_type_id'):
|
||||
return http_helper.response(code=400, message=_("Enter All required Dates for Permission request"),
|
||||
success=False)
|
||||
if not body.get('early_exit'):
|
||||
|
|
@ -189,10 +196,12 @@ class PermissionController(http.Controller):
|
|||
try:
|
||||
with request.env.cr.savepoint():
|
||||
permission = http.request.env['hr.personal.permission'].search([('id', '=', id)])
|
||||
permission_type_id = http.request.env['hr.personal.permission.type'].browse(int(body.get('permission_type_id')))
|
||||
if permission:
|
||||
permission_number = self.permission_number_decrement(employee, body['date_from'], body['date_to'])
|
||||
permission_number = self.permission_number_decrement(employee, body['date_from'], body['date_to'], permission_type_id)
|
||||
permission.write(
|
||||
{'employee_id': permission.employee_id.id, 'date_from': body['date_from'],
|
||||
'permission_type_id': permission_type_id.id,
|
||||
'date_to': body['date_to'],
|
||||
'early_exit': body['early_exit'],
|
||||
'date': body['date'],
|
||||
|
|
@ -212,6 +221,8 @@ class PermissionController(http.Controller):
|
|||
permission = http.request.env['hr.personal.permission'].search([('id', '=', id)])
|
||||
data = {
|
||||
"id": permission.id,
|
||||
"permission_type_id": permission_type_id.id,
|
||||
"permission_type_name": permission_type_id.name,
|
||||
"date": str(permission.date),
|
||||
"duration": permission.duration,
|
||||
"date_from": str(permission.date_from),
|
||||
|
|
@ -266,6 +277,8 @@ class PermissionController(http.Controller):
|
|||
data = {
|
||||
"id": permission.id,
|
||||
"date": str(permission.date),
|
||||
"permission_type_id": permission.permission_type_id.id,
|
||||
"permission_type_name": permission.permission_type_id.name,
|
||||
"duration": permission.duration,
|
||||
"date_from": str(permission.date_from),
|
||||
"date_to": str(permission.date_to),
|
||||
|
|
@ -349,12 +362,13 @@ class PermissionController(http.Controller):
|
|||
message=_(
|
||||
"You Have issue in your employee profile. please check with one of your team admins"),
|
||||
success=False)
|
||||
if not body.get('date_from') or not body.get('date_to'):
|
||||
if not body.get('date_from') or not body.get('date_to') or not body.get('permission_type_id'):
|
||||
return http_helper.response(code=400, message=_("Enter All required Dates for Permission request"),
|
||||
success=False)
|
||||
try:
|
||||
emp = []
|
||||
number_of_per = employee.contract_id.working_hours.permission_number
|
||||
permission_type_id = http.request.env['hr.personal.permission.type'].browse(int(body.get('permission_type_id')))
|
||||
number_of_per = permission_type_id.monthly_hours
|
||||
current_date = datetime.strptime(body['date_to'], DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
current_month = datetime.strptime(body['date_to'], DEFAULT_SERVER_DATETIME_FORMAT).month
|
||||
date_from = current_date.strftime('%Y-{0}-01'.format(current_month))
|
||||
|
|
@ -363,6 +377,7 @@ class PermissionController(http.Controller):
|
|||
date_to = current_date.strftime('%Y-{0}-31'.format(current_month))
|
||||
permissions = http.request.env['hr.personal.permission'].search([
|
||||
('employee_id', '=', employee.id),
|
||||
('permission_type_id', '=', int(body['permission_type_id'])),
|
||||
('state', '=', 'approve'),
|
||||
('date_from', '>=', date_from),
|
||||
('date_to', '<=', date_to)])
|
||||
|
|
@ -370,7 +385,7 @@ class PermissionController(http.Controller):
|
|||
balance = permission_number if permission_number >= 0 else 0
|
||||
|
||||
return http_helper.response(message="Data Found", data={'balance': balance,
|
||||
'permission_limit': employee.contract_id.working_hours.permission_hours})
|
||||
'permission_limit': permission_type_id.daily_hours})
|
||||
except (UserError, AccessError, ValidationError, Exception, Warning) as e:
|
||||
http.request._cr.rollback()
|
||||
error = str(e)
|
||||
|
|
@ -381,7 +396,7 @@ class PermissionController(http.Controller):
|
|||
message = validator.get_server_error(e, user)
|
||||
return http_helper.errcode(code=403, message=message)
|
||||
|
||||
def permission_number_decrement(self, employee_id, date_from, date_to):
|
||||
def permission_number_decrement(self, employee_id, date_from, date_to, permission_type_id):
|
||||
if employee_id:
|
||||
if not employee_id.first_hiring_date:
|
||||
raise Warning(_('You can not Request Permission The Employee have Not First Hiring Date'))
|
||||
|
|
@ -394,9 +409,10 @@ class PermissionController(http.Controller):
|
|||
date_from = current_date.replace(day=1)
|
||||
if current_month == 12:
|
||||
date_to = current_date.strftime('%Y-{0}-31'.format(current_month))
|
||||
number_of_per = employee_id.contract_id.working_hours.permission_number
|
||||
number_of_per = permission_type_id.monthly_hours
|
||||
employee_permissions = http.request.env['hr.personal.permission'].search([
|
||||
('employee_id', '=', employee_id.id),
|
||||
('permission_type_id', '=', permission_type_id.id),
|
||||
('state', '=', 'approve'),
|
||||
('date_from', '>=', date_from),
|
||||
('date_to', '<=', date_to)])
|
||||
|
|
|
|||
Loading…
Reference in New Issue