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

Viewed 3298

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 Answers
Related