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

如何在ir.values中添加user_id?为指定用户配置动作权限

How to Restrict the "Force Availability" Action to User ID=1 via ir.values in Odoo

Got it, let's get this sorted. Your goal is to make sure only the user with ID=1 can access the "Force Availability" action on stock pickings, right? The issue in your current code is how you're setting the user_id field—you can't just put the string "user" there; you need to reference the actual user record correctly.

Here's the corrected version of your XML record:

<record id="value_force_availability" model="ir.values">
    <field name="model_id" ref="stock.model_stock_picking" />
    <field name="name">Force Availability</field>
    <!-- Reference the user with ID=1 (default admin user in Odoo) -->
    <field name="user_id" ref="base.user_root"/>
    <field name="key2">client_action_multi</field>
    <field name="value" eval="'ir.actions.act_window,' + str(ref('action_force_availability'))"/>
    <field name="key">action</field>
    <field name="model">stock.picking</field>
</record>

Key Explanations:

  • The base.user_root is Odoo's built-in administrator user, which has an ID of 1 by default. Using ref("base.user_root") correctly links this ir.values record to that specific user.
  • If you're working with a custom user that has ID=1 (not the default admin), you can alternatively use <field name="user_id" eval="1"/> to directly specify the user ID.
  • With this change, only the user with ID=1 will see the "Force Availability" action in the stock picking views—all other users won't have access to it.

Quick Notes:

  • If you ever need to grant this action to multiple users, you'll need to create separate ir.values records for each user, each with their own user_id reference.
  • For broader access control (like granting to a group of users), you could use groups_id instead of user_id, but since you specifically wanted to target user ID=1, the above approach is the right fit.

内容的提问来源于stack exchange,提问作者user13270302

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 08:52:32