[UPD] odex_mobile: add app close timeout
This commit is contained in:
parent
0b9e62b870
commit
ce32cbbc45
|
|
@ -46,7 +46,7 @@ class AttendanceController(http.Controller):
|
|||
general_zoons = True if general else False
|
||||
for z in specific:
|
||||
value = {'id':z.id, 'name':z.zone, 'latitude':z.latitude, 'longitude':z.longitude, 'allowed_range':z.allowed_range,
|
||||
'loc_ch_intv': z.loc_ch_intv, 'loc_ch_dist':z.loc_ch_dist, 'srv_ch_tmout':z.srv_ch_tmout}
|
||||
'loc_ch_intv': z.loc_ch_intv, 'loc_ch_dist':z.loc_ch_dist, 'srv_ch_tmout':z.srv_ch_tmout, 'app_cl_tmout': z.app_cl_tmout}
|
||||
li.append(value)
|
||||
return http_helper.response(message="Data Found", data={'general_zoons':general_zoons, 'specific_zoons':li})
|
||||
except (UserError, AccessError, ValidationError, Exception, Warning) as e:
|
||||
|
|
@ -479,6 +479,65 @@ class AttendanceController(http.Controller):
|
|||
_logger.error(str(e))
|
||||
message = validator.get_server_error(e, user)
|
||||
return http_helper.errcode(code=403, message=message)
|
||||
|
||||
@http.route('/rest_api/v2/data-sync', type='http', auth='user', methods=['GET'], csrf=False)
|
||||
def data_sync(self, **kwargs):
|
||||
# Assuming that http_method, body, headers, and token are obtained via helper methods
|
||||
http_method, body, headers, token = http_helper.parse_request()
|
||||
|
||||
# Validate token
|
||||
result = validator.verify_token(token)
|
||||
if not result['status']:
|
||||
return http_helper.errcode(code=result['code'], message=result['message'])
|
||||
|
||||
# Verify user from token
|
||||
user = validator.verify(token)
|
||||
if not user:
|
||||
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
|
||||
)
|
||||
|
||||
# Find employee linked to the user
|
||||
employee = request.env['hr.employee'].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
|
||||
)
|
||||
|
||||
# Get the attendance zone for the employee or use general zone
|
||||
zone = request.env['attendance.zone'].search([('employee_ids', 'in', employee.id)], limit=1)
|
||||
if not zone:
|
||||
zone = request.env['attendance.zone'].search([('general', '=', True)], limit=1)
|
||||
|
||||
# Fetch the timeout value from the zone, default to 5 minutes if zone is not found or no value
|
||||
app_cl_tmout = zone.app_cl_tmout if zone else 5
|
||||
|
||||
# Get the current datetime and compare with last_active_time
|
||||
now = fields.Datetime.now()
|
||||
last_active_time = employee.last_active_time or now
|
||||
time_difference = now - last_active_time
|
||||
|
||||
# Check if the time difference exceeds the zone's timeout using timedelta
|
||||
if time_difference > timedelta(minutes=app_cl_tmout):
|
||||
return http_helper.response(
|
||||
code=200,
|
||||
message=f"Time difference is more than {app_cl_tmout} minutes",
|
||||
success=True,
|
||||
data={'force_checkout': True}
|
||||
)
|
||||
else:
|
||||
# Update last_active_time if force_checkout is False
|
||||
employee.write({'last_active_time': now})
|
||||
return http_helper.response(
|
||||
code=200,
|
||||
message=f"Time difference is less than {app_cl_tmout} minutes",
|
||||
success=True,
|
||||
data={'force_checkout': False}
|
||||
)
|
||||
|
||||
def send_msg(self, emp, msg, subject):
|
||||
if emp.user_id.partner_id:
|
||||
|
|
|
|||
|
|
@ -140,6 +140,11 @@ msgid ""
|
|||
" Expert Ltd Co cannot accept responsibility."
|
||||
msgstr ""
|
||||
|
||||
#. module: odex_mobile
|
||||
#: model:ir.model.fields,field_description:odex_mobile.field_attendance_zone__app_cl_tmout
|
||||
msgid "App Close Timeout - Minutes"
|
||||
msgstr "مهلة إغلاق التطبيق - دقائق"
|
||||
|
||||
#. module: odex_mobile
|
||||
#: code:addons/odex_mobile/controllers/project_timesheet.py:0
|
||||
#, python-format
|
||||
|
|
@ -2319,3 +2324,5 @@ msgstr "الساعات الإضافية"
|
|||
#, python-format
|
||||
msgid "Attendance hours"
|
||||
msgstr "ساعات الحضور"
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ class AttendanceZone(models.Model):
|
|||
loc_ch_intv = fields.Integer('Location Change Interval - Minutes', default=1)
|
||||
loc_ch_dist = fields.Integer('Location Change Distance - Meter', default=100)
|
||||
srv_ch_tmout = fields.Integer('Services Change Timeout - Minutes', default=5)
|
||||
app_cl_tmout = fields.Integer('App Close Timeout - Minutes', default=5)
|
||||
|
||||
auto_checkout = fields.Integer(string="Auto Checkout After" ,default=10)
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@ class HrEmployee(models.Model):
|
|||
fcm_token = fields.Char(string='FCM Token')
|
||||
attendance_log_ids = fields.One2many('attendance.log','employee_id',string="Attendance Log")
|
||||
message_sent = fields.Boolean(string="Message Sent", default=False)
|
||||
# Used internally by the API
|
||||
last_active_time = fields.Datetime(readonly=True)
|
||||
|
||||
|
||||
def user_push_notification(self, notification):
|
||||
def _get_access_token(json_file):
|
||||
"""Retrieve a valid access token that can be used to authorize requests.
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
<field name="loc_ch_intv" attrs="{'required':[('specific','=',True)],'invisible':[('specific','=',False)]}" class="oe_inline"/>
|
||||
<field name="loc_ch_dist" attrs="{'required':[('specific','=',True)],'invisible':[('specific','=',False)]}"/>
|
||||
<field name="srv_ch_tmout" attrs="{'required':[('specific','=',True)],'invisible':[('specific','=',False)]}"/>
|
||||
<field name="app_cl_tmout" attrs="{'required':[('specific','=',True)],'invisible':[('specific','=',False)]}"/>
|
||||
<field name="auto_checkout" />
|
||||
</group>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue