Odoo 15 hr_zk_attendance模块ValueError报错的解决咨询
解决Odoo 15 hr_zk_attendance模块的ValueError: Wrong value for zk.machine.attendance.punch_type: '255' 错误
错误原因
ZK考勤机同步考勤记录时返回了打卡类型值255,但zk.machine.attendance模型的punch_type字段未定义该可选值,且下载考勤记录的代码未对该值做兼容处理,导致Odoo创建记录时触发字段值验证失败。
解决方案
需要修改hr_zk_attendance模块的代码,以下是三种可行方案:
方案1:将255映射为现有打卡类型
- 打开文件:
custom_addons/hr_zk_attendance/models/zk_machine.py - 定位到
download_attendance方法(报错栈指向第166行附近) - 在构建
zk_attendance.create()的参数前,添加对punch_type值的判断处理:
# 示例代码(根据实际变量名调整) punch_type = record.get('punch_type') # 处理255值,映射为签到(可根据业务需求改为签退) if punch_type == '255': punch_type = 'check_in'
- 将处理后的
punch_type传入创建记录的参数中。
方案2:为punch_type字段新增255选项
- 找到定义
zk.machine.attendance模型的文件(通常是custom_addons/hr_zk_attendance/models/zk_machine_attendance.py) - 定位到
punch_type字段的定义,新增255对应的选项:
punch_type = fields.Selection([ ('check_in', '签到'), ('check_out', '签退'), ('255', '未知打卡类型'), # 可根据考勤机定义修改名称 # 保留原有其他选项 ], string='打卡类型')
- 回到
zk_machine.py的download_attendance方法,确保传入的punch_type值为字符串'255'(若原数据是数字需转成字符串)。
方案3:跳过无效的255类型记录
如果255代表无效记录,可直接跳过:
punch_type = record.get('punch_type') if punch_type == '255': continue # 跳过该条考勤记录
后续操作
代码修改完成后,在Odoo后台找到hr_zk_attendance模块,点击升级使修改生效。
内容的提问来源于stack exchange,提问作者MD REYAD HOSSAIN
相关产品推荐
相关产品推荐

