fix api hr mobile

This commit is contained in:
odex 2024-07-07 17:11:11 +03:00
parent d038e301d6
commit b1ee493681
1 changed files with 22 additions and 16 deletions

View File

@ -314,10 +314,12 @@ class AttendanceController(http.Controller):
"You are not allowed to perform this operation. please check with one of your team admins"),
success=False)
try:
print("******************employee.message_sent:",employee.message_sent)
if json.loads(body['in_zone']):
records = employee.attendance_log_ids.sudo().filtered(lambda r: str(r.date) == str(datetime.today().date()) and r.old == False)
for r in records:
r.old = True
employee.message_sent = False
return http_helper.response(message="Old Record Done", data={'status': True})
else:
@ -326,7 +328,6 @@ class AttendanceController(http.Controller):
limit=1)
if attendance.action == 'sign_in':
records = employee.attendance_log_ids.sudo().filtered(lambda r: r.old == False and str(r.date) == str(datetime.today().date()))
# records = employee.attendance_log_ids.sudo().filtered(lambda r: r.old == False and r.date == str(datetime.today().date()))
if records:
n = len(records)
last = records[n - 1]
@ -335,39 +336,43 @@ class AttendanceController(http.Controller):
if now > last:
diff = now - last
diff = diff.seconds / 60
zone = http.request.env['attendance.zone'].search([('employee_ids', 'in', employee.id)])
zone_general = http.request.env['attendance.zone'].search([('general', '=', True)])
zone = http.request.env['attendance.zone'].search([('employee_ids', 'in', employee.id)],limit=1)
zone_general = http.request.env['attendance.zone'].search([('general', '=', True)],limit=1)
auto = zone.auto_checkout or zone_general.auto_checkout or request.env.user.company_id.auto_checkout or 20
if diff >= auto:
attendance = http.request.env['attendance.attendance'].create({
'employee_id': employee.id,
'action':'sign_out',
'action': 'sign_out',
'action_type': 'auto',
'name': fields.datetime.now(),
# 'device_id': body.get('device_id'),
'zone': "%s,%s" % (body.get('longitude'), body.get('latitude')),
'longitude': body.get('longitude'),
'latitude': body.get('latitude'),
})
msg = (_("Auto Checkout successfully"))
subject = (_("Auto Checkout"))
msg = _("Auto Checkout successfully")
subject = _("Auto Checkout")
self.send_msg(employee, msg, subject)
records = employee.attendance_log_ids.sudo().filtered(
lambda r: str(r.date) == str(datetime.today().date()) and r.old == False)
for r in records:
r.old = True
return http_helper.response(message="Auto Checkout successfully", data={'status': True})
employee.message_sent = False
return http_helper.response(message="Auto Checkout successfully", data={'status': True})
else:
msg = (_("You are out of attendance zone you will be auto sin out "))
subject = (_("Auto Sign out"))
self.send_msg(employee, msg, subject)
return http_helper.response(message="Auto Checkout Fail and Send", data={'status': False})
if not employee.message_sent:
msg = _("You are out of attendance zone you will be auto sign out")
subject = _("Auto Sign out")
self.send_msg(employee, msg, subject)
employee.message_sent = True
return http_helper.response(message="Auto Checkout Fail and Send", data={'status': False})
else:
self.create_log(employee, body.get('longitude'), body.get('latitude'))
msg = (_("You are out of attendance zone you will be auto sin out "))
subject = (_("Auto Sign out"))
self.send_msg(employee, msg, subject)
return http_helper.response(message="Auto Checkout Fail and Send", data={'status': False})
if not employee.message_sent:
msg = _("You are out of attendance zone you will be auto sign out")
subject = _("Auto Sign out")
self.send_msg(employee, msg, subject)
employee.message_sent = True
return http_helper.response(message="Auto Checkout Fail and Send", data={'status': False})
else:
return http_helper.response(message="You are not Checked in yet", data={'status': True})
except Exception as e:
@ -377,6 +382,7 @@ class AttendanceController(http.Controller):
return http_helper.errcode(code=403, message=message)
def send_msg(self, emp, msg, subject):
print("*****************************send")
if emp.user_id.partner_id:
partner_id = emp.user_id.partner_id
partner_id.send_notification(subject, msg, data=None, all_device=True)