diff --git a/attendance_iot/controllers/kaoqin_test.py b/attendance_iot/controllers/kaoqin_test.py index 7fb7a43b8..abfa562cc 100644 --- a/attendance_iot/controllers/kaoqin_test.py +++ b/attendance_iot/controllers/kaoqin_test.py @@ -31,16 +31,22 @@ 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)]) - # 判断员工是否绑定多台设备 - 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 - })] - }) + 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({ + 'image_1920': data.get('photo'), + 'attendance_iot_ids': [(0, 0, { + 'employee_id': employee.id, + 'attendance_iot_id': iot.id, + 'attendance_address': '' + })] + }) _logger.info("-------------------------%s创建成功-------------------------------" % (employee.name)) return {"Result": 0, "Msg": "添加成功"}