From fd2f616db317943aaa4c14dd34bb2c993fae26e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= <9664676+pengyuthon@user.noreply.gitee.com> Date: Mon, 11 May 2026 18:05:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- attendance_iot/controllers/kaoqin_test.py | 26 ++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) 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": "添加成功"}