You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何基于登录用户筛选树形视图记录?权限配置遇报错求助

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:

  1. Wrong leaf node format: You wrote (uid,'=','1') which is backwards. Odoo requires domain leaves to follow the structure (field_name, operator, value)—here, uid gets replaced with the current user's actual ID (like 1), so Odoo tries to find a field named 1 on your model (which doesn't exist), hence the invalid leaf error.
  2. 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_uid matches 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:49:05