如何检查字段是否“包含" Odoo中的值 [英] How to check if field 'contains' the value in Odoo

查看:240
本文介绍了如何检查字段是否“包含" Odoo中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为给定类别的查看者的用户提供访问权限.

I'm trying to provide an access for users, who're viewers of the given category.

    <record id="rule_cost_centre_viewer" model="ir.rule">
        <field name="name">Access for the records for a cost_centre's viewer</field>
        <field name="model_id" ref="model_example_module"/>
        <field name="domain_force">[('user_id', 'in', category.viewers.ids)]</field>
        <field name="groups" eval="[(4,ref('group_example_module_user'))]"/>
    </record>

尝试未成功,我得到了:

The attempt was not successful, I got:

ValueError: <type 'exceptions.NameError'>: "name 'category' is not defined" while u"[('user_id', 'in', category.viewers.ids)]"

为清楚起见:

class Example(models.Model):
    _name = 'example.module'
    category = fields.Many2one('example.category', 'Category')

class Category(models.Model):
    _name = 'example.category'
    name = fields.Char('Category')
    viewers = fields.Many2many('res.users', 'example_category_rel', 'user_id', 'viewer_id', 'Viewers')

这是什么问题?

也许可以检查.

<field name="domain_force">[('category.viewers.ids', 'contains', user.id)]</field>

因为其他方法不起作用?..

since the other way is not working?..

推荐答案

应为:

<field name="domain_force">[('category.viewers', '=', user.id)]</field>

也许此解决方案有点尴尬,但它确实有效. 此处.

Maybe this solution is a bit awkward, but it's working. A similar question was answered here.

并尝试遵守Odoo的字段命名指南:category_idviewer_ids等.

And try to stay in Odoo's guideline for naming fields: category_id, viewer_ids and so on.

这篇关于如何检查字段是否“包含" Odoo中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆