Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2305 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
wrz 23
5685
8
mar 16
12197
3
lip 25
4081
0
maj 25
791
2
mar 24
2023