Skip to Content
Menu
This question has been flagged
2 Replies
5230 Views

I have 2 models like these:

class Category(models.Model):
    _name = 'mymodel.category'

    name = fields.Char('Name', required=True, translate=True)
    ...
    other fields
    ...

class Item(models.Model):
    _name = 'mymodel.item'

    name = fields.Char('Name', required=True, translate=True)
    category_id = fields.Many2one('mymodel.category', string='Category', required=True)

There are some rules on model Category.

The problem is​ that I want to show the records in model Item​ in tree view only if the user can see their category (defined as category_id in the model)

Avatar
Discard
Author

It works for Tree View, but in Form View if user change the ID parameter in URL, he can view every item

Author Best Answer

Thanks for your reply Gokulakrishnan Murugesan,
but this is not not what I want.

I'll try to describe my problem with a better​ example:
For example I have these records in the database, 2 categories e 3 items for each category.​

Category: Category_1

Category: Category_2

Item: Item_1_1

Item: Item_2_1

Item: Item_1_2

Item: Item_2_2

Item: Item_1_3

Item: Item_2_3

I also have 2 user:
User_1 that can access Category_1
User_2 that can access Category_2.

So, I want that User_1 can only see ​Item_1_1, Item_1_2, Item_1_3 in Item tree and form and User_2 can only see ​Item_2_1, Item_2_2, Item_2_3 in Item tree and form.

I hope to be clearer with this example.

Thanks.

Avatar
Discard
Best Answer

Hi,

Sample record rule

<record model="ir.rule" id="category_rule">
        <field name="name">Category Record Rule</field>
        <field name="model_id" ref="model_mymodel_category"></field>
         # If you need, you can add it below group condition otherwise its common to all
         <field name="groups" eval="[(4, ref('project_name.group_project_user'))]"></field>
         # You need to define domain rule here
         <field name="domain_force">[('manager_id', '=', user.employee_ids[0].id)]</field>
         <field eval="1" name="perm_write"></field>
         <field eval="1" name="perm_read"></field>
         <field eval="0" name="perm_unlink"></field>
         <field eval="0" name="perm_create"></field>
</record>

Otherwise you can define your domain here

category_id = fields.Many2one('mymodel.category', string='Category', required=True, domain=Your Condition)

Thanks

Avatar
Discard
Related Posts Replies Views Activity
2
Dec 23
12010
0
Oct 23
33
3
Oct 23
787
1
Oct 23
569
1
Aug 23
983