restrict check-in outside allowed working hours
This commit is contained in:
parent
56944f2a85
commit
e20d4d3fe2
|
|
@ -15,7 +15,7 @@ import logging
|
|||
_logger = logging.getLogger(__name__)
|
||||
from odoo.tools.translate import _
|
||||
import re
|
||||
|
||||
import pytz
|
||||
from odoo import fields
|
||||
|
||||
SENSITIVE_FIELDS = ['password', 'password_crypt', 'new_password', 'create_uid', 'write_uid']
|
||||
|
|
@ -189,6 +189,17 @@ class AttendanceController(http.Controller):
|
|||
employee = http.request.env['hr.employee'].sudo().search([('user_id', '=', user.id)], limit=1)
|
||||
if not employee:
|
||||
return http_helper.response(code=400, message=_("You are not allowed to perform this operation. please check with one of your team admins"), success=False)
|
||||
if body.get('action') and body.get('action') == 'sign_in':
|
||||
timezone = user.tz or 'GMT'
|
||||
local_tz = pytz.timezone(timezone)
|
||||
now_gmt = datetime.now(local_tz)
|
||||
current_time_float = now_gmt.hour + now_gmt.minute / 60.0
|
||||
calendar = employee.resource_calendar_id
|
||||
before_work = getattr(calendar, 'grace_hour_before_work', 8.0)
|
||||
after_work = getattr(calendar, 'grace_hour_after_work', 16.0)
|
||||
if before_work and after_work:
|
||||
if current_time_float < before_work or current_time_float > after_work:
|
||||
return http_helper.response(code=400, message=_("Dear employee, your working hours have not started yet."), success=False)
|
||||
if employee.device_id != body.get('device_id'):
|
||||
return http_helper.errcode(code=403, message=_("Device id not matching with already exist in system please contact system admin"))
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -2369,4 +2369,8 @@ msgstr "الساعات الإضافية"
|
|||
msgid "Attendance hours"
|
||||
msgstr "ساعات الحضور"
|
||||
|
||||
|
||||
#. module: odex_mobile
|
||||
#: code:addons/odex_mobile/controllers/rest_api_v2/attendance.py:0
|
||||
#, python-format
|
||||
msgid "Dear employee, your working hours have not started yet."
|
||||
msgstr "عزيزي الموظف دوام العمل لم يبدا بعد"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import logging
|
||||
import jwt
|
||||
import re
|
||||
import pytz
|
||||
import datetime
|
||||
import traceback
|
||||
from odoo import http, service, registry, SUPERUSER_ID,_
|
||||
|
|
@ -38,6 +39,22 @@ class Validator:
|
|||
return page
|
||||
|
||||
def get_attendance_check(self,employee):
|
||||
if not employee:
|
||||
return 'sign_out'
|
||||
user = employee.user_id
|
||||
timezone = user.tz or 'GMT'
|
||||
local_tz = pytz.timezone(timezone)
|
||||
now_gmt = datetime.datetime.now(local_tz)
|
||||
current_time_float = now_gmt.hour + now_gmt.minute / 60.0
|
||||
|
||||
calendar = employee.resource_calendar_id
|
||||
before_work = getattr(calendar, 'grace_hour_before_work', 8.0)
|
||||
after_work = getattr(calendar, 'grace_hour_after_work', 16.0)
|
||||
|
||||
if before_work and after_work:
|
||||
if current_time_float < before_work or current_time_float > after_work:
|
||||
return 'sign_out'
|
||||
|
||||
last = http.request.env['attendance.attendance'].sudo().search([('employee_id', '=', employee.id), ], order='name desc',
|
||||
limit=1)
|
||||
if last:
|
||||
|
|
|
|||
Loading…
Reference in New Issue