Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
1746 Переглядів

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 Відповіді Переглядів Дія
2
вер. 23
5160
8
бер. 16
11919
3
трав. 25
2689
0
трав. 25
175
2
бер. 24
1335