Odoo record rule restrictions

646 Views Asked by At

What I want to happen:

When the boolean no_edit is False and the user_id is false or the current user, the user should be able to edit the record.

What actually happens:

The records is always restricted for editting.

Python code of the fields:

user_id = fields.Many2one(
        comodel_name = 'res.users',
        string = 'User ID',
        readonly = True,
    )
no_edit = fields.Boolean(
        string = "No Edit",
        copy = False,
        default = False
    )

Domain:

['&', '|', ('no_edit', '=', False), ('user_id', '=', False), ('user_id', '=', user.id)]

Thanks in advance

1

There are 1 best solutions below

0
On BEST ANSWER

The domain should be:

[('no_edit', '=', False), '|', ('user_id', '=', False), ('user_id', '=', user.id)]

The one that you did evaluates the first part as an & operator:

('user_id', '=', False) & ('user_id', '=', user.id)

Because it is evaluated with "Reverse Polish Notation", for more information you can search or enter this link:

https://en.wikipedia.org/wiki/Reverse_Polish_notation