Odoo:ValueError:无效字段' user_id'在叶子里

时间:2016-04-06 07:18:38

标签: python openerp

我正在尝试创建规则,限制用户只在我的模块中查看树视图中的记录,但它给了我错误“user_id'字段不存在......

继承我的模特:

class help_desk(models.Model):
    _name = 'help_desk.help_desk'

    name = fields.Char(string="Title", required=True)
    number = fields.Char(string="Mobile", required=True)

以下是规则:

<record model="ir.rule" id="per_user_rule">
            <field name="name">User: see the individual Record</field>
            <field name="model_id" ref="model_help_desk_help_desk"/>
            <field name="domain_force">['|',('user_id','=',False),('user_id','=',user.id)]</field>
            <field name="groups" eval="[(4,ref('base.group_user'))]"/>
</record>

这是错误:

ValueError: Invalid field 'user_id' in leaf "<osv.ExtendedLeaf: ('user_id', '=', 9) on help_desk_help_desk (ctx: )>"

我猜,我必须将user_id字段添加到我的模型中,但我如何将其与当前用户联系起来?

3 个答案:

答案 0 :(得分:2)

我找到了解决方案。我在我的模型中添加了以下字段:

user_id = fields.Many2one('res.users', string='User', track_visibility='onchange', readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.user)

它将当前用户作为默认值。

答案 1 :(得分:1)

将user_id更改为create_uid

create_uid - 定义创建记录的用户

  <field name="domain_force">[('create_uid','=',uid)]</field>

答案 2 :(得分:0)

.py文件 class help_desk(models.Model):     _name =&#39; help_desk.help_desk&#39;

name = fields.Char(string="Title", required=True)
number = fields.Char(string="Mobile", required=True)
user_id = fields.Many2one('res.users', string='User', track_visibility='onchange', readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.user)

安全/ .xml文件 ir.rule

<record model="ir.rule" id="per_user_rule">
            <field name="name">User: see the individual Record</field>
            <field name="model_id" ref="model_help_desk_help_desk"/>
            <field name="domain_force">['|',('user_id','=',False),('user_id','=',user.id)]</field>
            <field name="groups" eval="[(4,ref('base.group_user'))]"/>
</record>