0
votes

How to filter records for tree view based on logged in user. For Admin, Manager i want show every record , for normal user I want show records created by that particular user only.

Below code sample I tried

For manager uid=12

For admin uid=1

 <field name="domain">[('|',('create_uid','=',uid),('|',(uid,'=','1'),(uid,'=','12')))]</field>

Above code sample is throwing error

"ValueError: Invalid leaf ['|', ['create_uid', '=', 1], ['|', [1, '=', '1'], [1, '=', '12']]]"

2

2 Answers

1
votes

Row-level access rules are defined in the ir.rule model and can be created by adding a corresponding xml file to the module. The file is usually stored under security/ folder in your module directory.

For example I've taken user.purchase.records as the model

<?xml version="1.0" encoding="utf-8"?>
<odoo>
  <data>
    <record id="user_purchase_record_rule" model="ir.rule">
      <field name="name">Records created by current user only</field>
      <field name="model_id" ref="model_user_purchase_records"/>
      <field name="domain_force">[('create_uid','=',user.id)]</field>
      <field name="groups" eval="[(4,ref('base.group_user'))]"/>
    </record>
  </data>
</odoo>

Finally add this file path in your manifest.py file.

0
votes

A domain it's composed by 3 elements, (field_in_your_model, operator, value), I don't know if you are working with a known model or it's your definition, but you got that error because uid it's a reserved word for odoo, not a field in a model. And the best approach for your requirement its make rules, for your groups of users, something like sale groups:

Rule for Sale / User: Own Documents Only:

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

I hop this answer can be helpful you.