63 lines
2.8 KiB
Python
63 lines
2.8 KiB
Python
from venv import create
|
|
|
|
from odoo.http import Controller, request, route
|
|
from datetime import datetime
|
|
from odoo import models, fields, api, http, SUPERUSER_ID, _
|
|
|
|
|
|
class BusController(Controller):
|
|
|
|
@route('/api/v1/addFace', methods=['POST'], type='json', auth='none', csrf=False)
|
|
def get_model_kaoqin(self):
|
|
"""
|
|
获取用户录入考勤机数据,和系统内用户绑定关联
|
|
:return:
|
|
"""
|
|
data = request.httprequest.json
|
|
user_name = data.get('name')
|
|
name = data.get('sn')
|
|
# validity_period = datetime.strptime(data.get('validity_period'), '%Y-%m-%d').date()
|
|
attendance_iot_id = request.env["attendance.iot"].search([('name', '=', name)])
|
|
if not attendance_iot_id:
|
|
request.env["attendance.iot"].create({
|
|
'name': name,
|
|
})
|
|
employee = request.env(user=SUPERUSER_ID)["hr.employee"].search([('name', '=', user_name)])
|
|
# 判断员工是否绑定多台设备
|
|
if employee and attendance_iot_id not in employee.attendance_iot_ids.mapped('attendance_iot_id'):
|
|
employee.write({
|
|
'image_1920': data.get('photo'),
|
|
'attendance_iot_ids': [(0, 0, {
|
|
'employee_id': employee.id,
|
|
'attendance_address': self.get_equipment_company(data.get('sn')),
|
|
'attendance_iot_id': attendance_iot_id.id
|
|
})]
|
|
})
|
|
|
|
|
|
print("---------------------------------------------测试成功---------------------------------------")
|
|
return {"Result": 0, "Msg": "添加成功"}
|
|
|
|
@route('/api/v1/record/face', methods=['POST'], type='json', auth='none', csrf=False)
|
|
def get_model_identify(self):
|
|
"""
|
|
获取上传识别成功记录
|
|
:return:
|
|
"""
|
|
data = request.httprequest.json
|
|
user_id = data.get('logs')[0].get('user_id')
|
|
employee_id = request.env(user=SUPERUSER_ID)["hr.employee"].search([('user_id', '=', user_id.id)])
|
|
recog_time_str = data.get('logs')[0].get("recog_time")
|
|
checkin_time = datetime.strptime(recog_time_str, "%Y-%m-%d %H:%M:%S")
|
|
attendance_iot_id = request.env(user=SUPERUSER_ID)["attendance.iot"].search([('name', '=', data.get('sn'))])
|
|
if employee_id:
|
|
request.env(user=SUPERUSER_ID)["hr.attendance.detail"].create({
|
|
'employee_id': employee_id.id, # 员工
|
|
'checkin_time': checkin_time, # 打卡时间
|
|
'source': 'iot', # 打卡来源
|
|
'attendance_iot_id': attendance_iot_id.id, # 打卡设备
|
|
'location_title': data.get('logs')[0].get("location").get('address'), # 打卡地点
|
|
})
|
|
print("---------------------------------------------测试成功---------------------------------------")
|
|
return {"Result": 0, "Msg": "添加成功"}
|