如何在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_rootis Odoo's built-in administrator user, which has an ID of 1 by default. Usingref("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.valuesrecords for each user, each with their ownuser_idreference. - For broader access control (like granting to a group of users), you could use
groups_idinstead ofuser_id, but since you specifically wanted to target user ID=1, the above approach is the right fit.
内容的提问来源于stack exchange,提问作者user13270302
相关产品推荐
相关产品推荐

