diff --git a/attendance_iot/__manifest__.py b/attendance_iot/__manifest__.py index 7652b0588..1003adabb 100644 --- a/attendance_iot/__manifest__.py +++ b/attendance_iot/__manifest__.py @@ -14,6 +14,7 @@ 'data': [ 'security/ir.model.access.csv', 'views/attendance_iot_datas.xml', + 'views/attendance_iot_user_views.xml', 'views/attendance_iot_manager_views.xml', 'views/attendance_iot_views.xml', 'views/inherit_hr_employee_views.xml', diff --git a/attendance_iot/controllers/kaoqin_test.py b/attendance_iot/controllers/kaoqin_test.py index b772649d0..0d3cde185 100644 --- a/attendance_iot/controllers/kaoqin_test.py +++ b/attendance_iot/controllers/kaoqin_test.py @@ -1,3 +1,5 @@ +from venv import create + from odoo.http import Controller, request, route from datetime import datetime from odoo import models, fields, api, http, SUPERUSER_ID, _ @@ -28,9 +30,23 @@ 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') # 姓名 - phone = request.jsonrequest.get('content') # 电话 - print(name, phone) + 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 + })] + }) return { "Result": 0, "Msg": "更新成功" diff --git a/attendance_iot/models/__init__.py b/attendance_iot/models/__init__.py index 6ecccf0e1..8b3a38af1 100644 --- a/attendance_iot/models/__init__.py +++ b/attendance_iot/models/__init__.py @@ -1,4 +1,5 @@ from . import hr_employee +from . import attendance_iot_user from . import attendance_iot from . import attendance_iot_datas from . import attendance_iot_manager diff --git a/attendance_iot/models/attendance_iot.py b/attendance_iot/models/attendance_iot.py index b28f7c069..9e4c3d949 100644 --- a/attendance_iot/models/attendance_iot.py +++ b/attendance_iot/models/attendance_iot.py @@ -11,3 +11,5 @@ class AttendanceIot(models.Model): attendance_address = fields.Char(string="设备地址") broker = fields.Char(string='服务器地址/ip') port = fields.Char(string='端口号') + id_valid = fields.Datetime(string="设备有效期") + diff --git a/attendance_iot/models/attendance_iot_manager.py b/attendance_iot/models/attendance_iot_manager.py index b3fe1b2b2..2d43dac3c 100644 --- a/attendance_iot/models/attendance_iot_manager.py +++ b/attendance_iot/models/attendance_iot_manager.py @@ -14,8 +14,6 @@ class AttendanceIotManager(models.Model): attendance_iot_id = fields.Many2one('attendance.iot', string="设备号") attendance_address = fields.Char(string="设备地址") - employee_id = fields.Many2one('hr.employee', string="员工") - id_valid = fields.Date(string="数据有效期") data_selection = fields.Selection([('mqtt', 'mqtt'), ('api', 'api')], default="mqtt", string="数据类型") def action_attendance_iot_manager(self): @@ -29,9 +27,10 @@ class AttendanceIotManager(models.Model): @api.model_create_multi def create(self, vals_list): - for vals in vals_list: - if vals['data_selection'] == 'mqtt': - self.mqtt_request(self, vals['attendance_number'], 'addUser') + pass + # for vals in vals_list: + # if vals['data_selection'] == 'mqtt': + # self.mqtt_request(self, vals['attendance_number'], 'addUser') return super().create(vals_list) def mqtt_request(self, attendance_number, data): @@ -88,3 +87,19 @@ class AttendanceIotManager(models.Model): _logger.info(f"操作失败,返回错误码: {res.get('code')}") client.disconnect() + def employee_message(self): + domain = [('attendance_iot_id', '=', self.attendance_iot_id.id)] + return { + 'name': '员工列表', + 'type': 'ir.actions.act_window', + 'res_model': 'attendance.iot.user', + 'view_mode': 'tree', + 'domain': domain, + 'target': 'current' + } + + + + + + diff --git a/attendance_iot/models/attendance_iot_user.py b/attendance_iot/models/attendance_iot_user.py new file mode 100644 index 000000000..b469e4e83 --- /dev/null +++ b/attendance_iot/models/attendance_iot_user.py @@ -0,0 +1,13 @@ +from odoo import api, fields, models, tools +from odoo.exceptions import ValidationError + + +class AttendanceIotUser(models.Model): + _name = 'attendance.iot.user' + + attendance_iot_id = fields.Many2one('attendance.iot', string="设备号") + attendance_address = fields.Char(string="设备地址") + employee_id = fields.Many2one('hr.employee', string="员工") + department_id = fields.Many2one(related='employee_id.department_id', string="部门") + company_id = fields.Many2one(related='employee_id.company_id', string="公司", store=True) + id_valid = fields.Date(string="有效日期") diff --git a/attendance_iot/models/hr_employee.py b/attendance_iot/models/hr_employee.py index 57ff9a2cf..67a137fff 100644 --- a/attendance_iot/models/hr_employee.py +++ b/attendance_iot/models/hr_employee.py @@ -6,4 +6,4 @@ class HrEmployee(models.Model): _inherit = "hr.employee" _description = "考勤机和用户信息的绑定" - attendance_iot_ids = fields.One2many('attendance.iot.manager', 'employee_id', string="考勤机信息") + attendance_iot_ids = fields.One2many('attendance.iot.user', 'employee_id', string="考勤机信息") diff --git a/attendance_iot/security/ir.model.access.csv b/attendance_iot/security/ir.model.access.csv index c146197a7..4570dc0aa 100644 --- a/attendance_iot/security/ir.model.access.csv +++ b/attendance_iot/security/ir.model.access.csv @@ -2,4 +2,5 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_attendance_iot,attendance_iot,model_attendance_iot,base.group_user,1,1,1,1 access_attendance_iot_manager,attendance_iot_manager,model_attendance_iot_manager,base.group_user,1,1,1,1 access_attendance_iot_manager_wizard,attendance_iot_manager_wizard,model_attendance_iot_manager_wizard,base.group_user,1,1,1,1 -access_attendance_iot_datas,attendance_iot_datas,model_attendance_iot_datas,base.group_user,1,1,1,1 \ No newline at end of file +access_attendance_iot_datas,attendance_iot_datas,model_attendance_iot_datas,base.group_user,1,1,1,1 +access_attendance_iot_user,attendance_iot_user,model_attendance_iot_user,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/attendance_iot/views/attendance_iot_manager_views.xml b/attendance_iot/views/attendance_iot_manager_views.xml index 45004e72c..63bd93fc5 100644 --- a/attendance_iot/views/attendance_iot_manager_views.xml +++ b/attendance_iot/views/attendance_iot_manager_views.xml @@ -7,9 +7,8 @@ - - +