Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
2311 Zobrazení

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)]" 

Avatar
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
zář 23
5687
8
bře 16
12198
3
čvc 25
4096
0
kvě 25
793
2
bře 24
2028