Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2327 มุมมอง

how can i make a self-defined menuitem only visible to user based on some conditions?

for example, can i 

menuitem something domain="[('company_id','=',company_id)]" 

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

In Odoo, you can control the visibility of a menu item based on certain conditions by using the groups attribute in the menu item definition. The groups attribute allows you to specify which user groups have access to the menu item.
However, directly using a domain in the menu item definition is not supported. Instead, you can create an action for the menu item and set the domain in the context of that action.
Here's an example of two methods to achieve this:

1. Define an action with a domain in your model:

<record id="action_menu_item" model="ir.actions.act_window">
 
  <field name="name">Your Action Name</field>
<field name="res_model">your.model</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="your_module.view_tree_id"/>
<field name="domain">[('company_id','=',company_id)]</field>
</record>

   



Make sure to replace your.model with the actual model you're working with and your_module.view_tree_id with the actual ID of the tree view.


2. Create a menu item associated with a group:

<menuitem id="menu_item_id" name="Menu Item Name" parent="your_parent_menu_id" action="action_menu_item" groups="your_module.group_name"/>

   


Replace menu_item_id, Menu Item Name, your_parent_menu_id, your_module.group_name with appropriate values. and create security groups with your requirements

<record id="group_name" model="ir.rule">
            <field name="name">User group name</field>
            <field name="model_id" ref="model_id"/>
<field name="domain_force">[('company_id', 'in', company_ids)]</field>
 </record>

   



Assign users to the security group. Users in this group will have access to the menu item based on the defined domain.


Hope it helps

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Server actions in menuItem แก้ไขแล้ว
2
ก.ย. 23
5712
Default value for new object - Odoo 8 แก้ไขแล้ว
8
มี.ค. 16
12227
naked domain set up แก้ไขแล้ว
3
ก.ค. 25
4122
0
พ.ค. 25
827
2
มี.ค. 24
2049