diff --git a/attendance_iot/controllers/kaoqin_test.py b/attendance_iot/controllers/kaoqin_test.py index ad39fbfb2..7fb7a43b8 100644 --- a/attendance_iot/controllers/kaoqin_test.py +++ b/attendance_iot/controllers/kaoqin_test.py @@ -31,24 +31,16 @@ class BusController(Controller): if not attendance_iot_id: request.env(user=SUPERUSER_ID)["attendance.iot"].create({'name': name, }) employee = request.env(user=SUPERUSER_ID)["hr.employee"].search([('name', '=', user_name)]) - all_company_iots = request.env["attendance.iot"].search([ - ('company_id', '=', employee.company_id.id) - ]) - for iot in all_company_iots: - exist = employee.attendance_iot_ids.filtered( - lambda l: l.attendance_iot_id.id == iot.id - ) - if not exist: - employee.write({ - 'avatar_image': data.get('photo'), - 'image_1920': data.get('photo'), - 'attendance_iot_ids': [(0, 0, { - 'employee_id': employee.id, - 'attendance_iot_id': iot.id, - 'attendance_address': '' - })] - }) - _logger.info(f"-------------{employee.name}人脸更新触发------人脸数据{data.get('photo')}-------------") + # 判断员工是否绑定多台设备 + 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': '', + 'attendance_iot_id': attendance_iot_id.id + })] + }) _logger.info("-------------------------%s创建成功-------------------------------" % (employee.name)) return {"Result": 0, "Msg": "添加成功"}