From 730c6804aff353b65cf2b9c19fea31b11a61a4d7 Mon Sep 17 00:00:00 2001
From: zhou <123@>
Date: Wed, 4 Jun 2025 21:27:39 +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 | 66 +++++++++----------
.../models/hr_attendance_detail_wechat.py | 2 +
.../hr_attendance_detail_wechat_views.xml | 4 +-
3 files changed, 35 insertions(+), 37 deletions(-)
diff --git a/attendance_iot/controllers/kaoqin_test.py b/attendance_iot/controllers/kaoqin_test.py
index 0d3cde185..19233bfd2 100644
--- a/attendance_iot/controllers/kaoqin_test.py
+++ b/attendance_iot/controllers/kaoqin_test.py
@@ -30,23 +30,9 @@ class BusController(Controller):
@route('/api/v1/user/inf_photo', methods=['POST'], type='json', auth='public')
def get_model_definitions(self):
- name = request.jsonrequest.get('sn') #设备序列号
- attendance_iot_id = self.env["attendance.iot"].search([('name', '=', name)])
- # 创建设备
- if not attendance_iot_id:
- self.env["attendance.iot"].create({
- 'name': name,
- })
- user_id = request.jsonrequest.get('content')[0]['user_id'] #用户id
- employee = self.env["hr.employee"].search([('user_id', '=', user_id)])
- # 判断员工是否绑定多台设备
- if employee and attendance_iot_id not in employee.attendance_iot_ids.mapped('attendance_iot_id'):
- employee.write({
- 'attendance_iot_ids': [(0, 0, {
- 'employee_id': employee.id,
- 'attendance_iot_id': attendance_iot_id.id
- })]
- })
+ name = request.jsonrequest.get('sn') # 姓名
+ phone = request.jsonrequest.get('content') # 电话
+ print(name, phone)
return {
"Result": 0,
"Msg": "更新成功"
@@ -74,19 +60,26 @@ class BusController(Controller):
"""
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()
- employee_id = request.env(user=SUPERUSER_ID)["hr.employee"].search([('name', '=', user_name)])
- attendance_iot = request.env(user=SUPERUSER_ID)["attendance.iot.manager"]
- if not attendance_iot.search([('employee_id', '=', employee_id.id), ('attendance_number', '=', data.get('sn'))]):
- employee_id.write({
+ 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
+ })]
})
- attendance_iot.create({
- 'data_selection': "api",
- 'attendance_number': data.get('sn'),
- 'attendance_address': self.get_equipment_company(data.get('sn')),
- 'employee_id': employee_id.id,
- })
+
+
print("---------------------------------------------测试成功---------------------------------------")
return {"Result": 0, "Msg": "添加成功"}
@@ -97,15 +90,18 @@ class BusController(Controller):
:return:
"""
data = request.httprequest.json
- user_name = data.get('logs').get('user_id')
- employee_id = request.env(user=SUPERUSER_ID)["hr.employee"].search([('user_id', '=', user_name.id)])
- attendance_iot = request.env(user=SUPERUSER_ID)["attendance.iot.datas"]
- if not attendance_iot.search(
- [('employee_id', '=', employee_id.id), ('attendance_number', '=', data.get('sn'))]):
- attendance_iot.create({
- 'attendance_number': data.get('sn'),
- 'attendance_date': data.get('logs').get('recog_time'),
+ 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]["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.details"].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]["location"].get('address'),
})
print("---------------------------------------------测试成功---------------------------------------")
return {"Result": 0, "Msg": "添加成功"}
diff --git a/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py b/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py
index c1f14a773..8ee8ee671 100644
--- a/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py
+++ b/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py
@@ -40,6 +40,8 @@ class HrAttendanceDetail(models.Model):
employee_id = fields.Many2one('hr.employee', string="员工", readonly=True)
company_id = fields.Many2one('res.company', string="公司", related="employee_id.company_id", store=True)
department_id = fields.Many2one('hr.department', string="部门", related="employee_id.department_id", readonly=True, store=True)
+ source = fields.Selection([('iot', '考勤机'), ('mini_programs', '小程序')], string="来源")
+ attendance_iot_id = fields.Many2one('attendance.iot', string="设备号")
userid = fields.Char(string='userid')
groupname = fields.Char(string='打卡规则名称')
checkin_type = fields.Char(string='打卡类型')
diff --git a/yuthon_hr_attendance/views/hr_attendance_detail_wechat_views.xml b/yuthon_hr_attendance/views/hr_attendance_detail_wechat_views.xml
index 1fd684a5e..f9d5a49fc 100644
--- a/yuthon_hr_attendance/views/hr_attendance_detail_wechat_views.xml
+++ b/yuthon_hr_attendance/views/hr_attendance_detail_wechat_views.xml
@@ -37,8 +37,8 @@
-
-
+
+