如何基于登录用户筛选树形视图记录?权限配置遇报错求助
Fixing Odoo Tree View Domain Filter for User-Specific Access
Let's figure out why your domain is throwing that error and get the user-specific filtering working properly for your tree view.
Why You're Seeing That Invalid Leaf Error
Your original domain has two big issues:
- Wrong leaf node format: You wrote
(uid,'=','1')which is backwards. Odoo requires domain leaves to follow the structure(field_name, operator, value)—here,uidgets replaced with the current user's actual ID (like1), so Odoo tries to find a field named1on your model (which doesn't exist), hence the invalid leaf error. - Broken OR condition nesting: The way you nested your
|operators was structured incorrectly, making the entire domain unparseable by Odoo.
Correct User Filtering Logic
We need a domain that does two things:
- Shows every record to admins (uid=1) and managers (uid=12)
- Only shows records created by the current user for everyone else
Solution 1: Dynamic Domain with eval (Best Approach)
This is the cleanest and easiest to maintain way to implement this. We use the eval attribute to generate the domain based on who's logged in:
<field name="domain" eval="[] if uid in (1, 12) else [('create_uid', '=', uid)]"/>
How this works:
- If the current user is admin (uid=1) or manager (uid=12), the domain is empty (
[]), which means all records are displayed. - For regular users, the domain filters records where
create_uidmatches their user ID—so they only see their own creations.
Verify the Fix
After updating your domain with Solution 1:
- Log in as uid=1 or uid=12: You'll see all records in the tree view.
- Log in as any other user: Only records you created will be visible.
内容的提问来源于stack exchange,提问作者SHIVA REDDY
相关产品推荐
相关产品推荐

