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

I am trying to provide access for users who are viewers of this category.

    <record id="rule_cost_centre_viewer" model="ir.rule">
        <field name="name">Access for the records for a cost_centre 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 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 is the problem?

Maybe there is an opportunity to check ..

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

      

since the other way doesn't work? ..

+3


source to share


1 answer


It should be:

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

      



This solution might be a little awkward, but it works. A similar question has been answered here .

And try to stay in Odoo directive for naming fields: category_id

, viewer_ids

etc.

+3


source







All Articles