gpt4 book ai didi

python - 将用户添加到组访问权限

转载 作者:行者123 更新时间:2023-11-30 22:07:58 25 4
gpt4 key购买 nike

我想在 res.groups 上存在的组中添加用户但不知道为什么他不加这个群这是我的代码 python

class access_teacher1(models.Model):

_inherit = 'res.users'

def create(self, cr, uid, vals, context=None):

new_id = super(access_teacher1, self).create(cr, uid, vals, context=context)
if self.browse(cr, uid, new_id, context=context).is_teacher:
self.write(cr, uid, [new_id], {'password': vals['login']}, context=context)

res_groups = self.pool['res.groups']
group_id = self.pool['ir.model.data'].get_object(cr, uid,'pronote','proschool_teacher')
res_groups.write(cr, uid, [group_id], {'users': [new_id]}, context=context)
return new_id

问题在 {'users': [new_id]} 上停止如何解决这个问题

最佳答案

试试这个:

res_groups.write(cr, uid, [group_id.id], {'users': [(4,new_id)]}, context=context)

原因是 Odoo 使用特殊的命令格式针对 One2many 和 Many2many 字段写入值

您可以在以下位置阅读更多相关信息:

https://github.com/odoo/odoo/blob/9e8f70e4849b0eeaca8b5cf51372ecfa23dc561b/openerp/models.py#L3724-L3761

关于python - 将用户添加到组访问权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52327166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com