Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
4 Replies
68675 Tampilan

Hello,

   I created a custom hr module and was wondering how I can modify the groups attribute for the top Human Resources menu item.  What I would like to do is remove one of the groups on the original menu item so that users in that group cant see it.  Is there a way to inherit the original menu item in my custom hr module, and use xpath to modify it? Or is there another (easier) way to do it?

Avatar
Buang
Jawaban Terbai

Hello Eric, menu entries are usually defined with the 'menuitem' XML tag (e.g. for Project>Configuration see this link):

<menuitem name="menuName" id="mod_id.menu_id" ... />

At installing the module, however, they are stored as records of the 'ir.ui.menu' object type. where the many2many relationship to 'res.groups' is defined.

Given that, it is perfectly possible to use 'record' XML tags to update 'ir.ui.menu' records by providing 'model' and 'id' attributes to identify the existing record. E.g. Project>Configuration (source here):

<record model="ir.ui.menu" id="mod_id.menu_id">
  <field name="groups_id" eval="[(6,0,[ref('group_my_restricted_group')])]"/>
</record>

Just remember 'groups_id' is a many2many relationship, so you will require to provide an appropriate tuple to update the relationship (the above example replaces all groups). Look for the documentation of 'write(vals)' here for a reference.

Regards,

Marvin

Avatar
Buang
Penulis

This is a very simple solution. Thank you!

I didn't quite understand that. Let's say I would like to add a sub-menu to Sales/Sales, what I did was to write the following code in my custom module:

<menuitem name="Daily Transports" id="daily_transports_menu" sequence="10" parent="base.menu_base_partner" action="daily_transports_action"/>

but I didn't get it to appear under the sales submenus

I tried this in odoo 16 but it doesn't work, can you please, tell me what I'm doing bad.
<record model="ir.ui.menu" id="hr_payroll.menu_hr_payroll_payslips ">
<field name="name">Payroll</field>
</record>

I use this code to change the menu payslip to payroll from the payroll module

Jawaban Terbai

To redefine menu item you don't need xpath ,, simply redfine that in your xml file,, with correct id reference ,, here change  id as " hr.menu_hr_root"

Orginal:-

<menuitem name="Human Resources"
            id="menu_hr_root"
            groups="base.group_hr_manager,base.group_hr_user,base.group_user"
            sequence="90"/>

you can evict group from Human Resources menuitem like this:-

<menuitem name="Human Resources"
            id="hr.menu_hr_root"
            sequence="90"/>

 

Avatar
Buang