How to check if field 'contains' the value in Odoo

眉间皱痕 提交于 2019-12-10 20:28:37

问题


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)]"

For the sake of clarity:

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')

What's the problem in here?

Maybe there's a possibility to check.

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

since the other way is not working?..


回答1:


It should be:

<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.

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



来源:https://stackoverflow.com/questions/45143568/how-to-check-if-field-contains-the-value-in-odoo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!