This question has been flagged
7 Replies
46965 Views

I'd like to change the label of a couple menu options. For example, I want to change the name of the main menu option Sales (crm). I know how to achieve this from the user interface, but it's better to do it through code.

I read in other posts that the only way to do this is declaring a new menuitem with the same ID of the menuitem you want to change. So, I want to change these ones (main menu option and submenu):

<menuitem name="Sales"
    id="menu_base_partner"
    groups="base.group_sale_salesman"
    sequence="20"/>
<menuitem id="base.menu_sales" parent="base.menu_base_partner" name="Sales" sequence="1" />

So I put this in my module code:

<menuitem name="My new string"
    id="menu_base_partner"
    groups="base.group_sale_salesman"
    sequence="20"/>
<menuitem id="base.menu_sales" parent="base.menu_base_partner" name="My new string" sequence="1" />

What is happening is that the top menu option "Sales" is turned into "My new string", which is correct. However, the submenu is not being changed and even more, the other submenus (which were in blue color) are being transformed in dropdown options.

If I remove the line <menuitem id="base.menu_sales" parent="base.menu_base_partner" name="My new string" sequence="1" />, the top menu option "Sales" is not being altered, and if I leave that line and add another menuitem whose parent is base.menu_sales, then both menu and submenu options are replaced well but the other submenus are being transformed in dropdown options.

Can anyone help me, please?

EDIT

I tried next code too, but nothing changed. I'm sure that the XML ID I'm using is right (I'm getting it from Configuration > User interface > Menu items)

<record model="ir.ui.menu" id="base.menu_base_partner">
     <field name="name">My New Menu Name</field>
</record>

Avatar
Discard

sorry for multiple answers, you need to change id="menu_base_partner" to id="base.menu_base_partner"

please let me know if that worked...??

Author

@Jesus and @Baiju, with id="base.menu_base_partner", there are no errors but the menuitem name does not change.

Best Answer

Hi,

For changing name of an existing menu item, you can do it like this,

<record model="ir.ui.menu" id="sales_team.menu_sale_config">
<field name="name">Configuration</field>
</record>

Refer:  How To Inherit Menu Item And Make Changes in Odoo

Thanks

Avatar
Discard
Best Answer

Hello Juan, menu entries are stored as records of the 'ir.ui.menu' object type, so it is 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="name">My New Menu Name</field>
    </record>

'record' XML tags are processed differently, so you only require to provide fields/values for anything you want to modify.

Regards,
Marvin

Edit: I created a simple module 'hr_menu_mv' to shorten the top level "Human Resources" menu to "HR", just to verify this approach, below are sources for the three files required (verified with v7.0 and v8.0):

__init__.py:

# empty as no python modules are required to be imported

__openerp__.py:

{
    'name': "HR Menu Mv",
    'version': "0.1",
    'category': "Human Resources",
    'depends': ['hr'],
    'data': ['hr_menu_mv_view.xml'],
    'installable': True,
    'auto_install': False,
    'application': False,
}

hr_menu_mv_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record model="ir.ui.menu" id="hr.menu_hr_root">
            <field name="name">HR</field>
        </record>
    </data>
</openerp>

I'm omitting translations just to keep the example small and readable.

Avatar
Discard
Author

This is the way I like the most, but nothing happened. I tried this: My New Menu Name --- I am sure that the XML ID of the menu I want to change is that one (base.menu_base_partner), because I am looking for it in Configuration > User interface > Menu items. I am writing that code from my customized module. Do you see anything wrong?

Author

I am sorry, I always forget that when I paste XML tags in a comment, these ones dissapear, so I am going to edit the question so you can check what I did.

Author

Thank you for your patience Marvin. I did exactly what you did: I created a new module with your lines (for v7) However, nothing happened again. In my case, the XML ID of the main menu option of Human Resources is "hr.menu_hr_main". I tried with both, but still nothing. I restarted and updated the service and then pressed F5. No results.

Juan, I have verified that the "base.menu_base_partner" menu entry is defined four time in v7.0 sources, once in the "base" module, and then three times in the following modules: "crm", "crm_helpdesk", "sale". If you're using any of the previous modules, chances are that your entry (either 'record' or 'menuitem') that renames "base.menu_base_partner" is not applied last (so it gets renamed to Sales again). In order to guarantee that your changes are applied last, you can declare module dependencies to any other modules that rename "base.menu_base_partner" ("crm", "crm_helpdesk", "sale") so your module will be installed after all of them.

Author

One minute! I have just checked my database and the record name for that menu was changed well, as you said! But for one reason I can't see the changes in the browser.

Author

I'm racking my brains to know why I can't see the changes on the browser, I tried a lot of things, but still nothing. One thing is clear: the code you gave me is changing my database, and it's working for you, so your answer is right. I will open another question to ask about my other problem, but this one is solved. Thank you a lot for your patience, Marvin.

Author

I had to synchronize terms to see the changes: https://www.odoo.com/forum/help-1/question/why-cant-i-see-changes-made-on-the-table-ir-ui-menu-trying-to-change-a-menuitem-67732

Best Answer

Try this:-

<menuitem name="New String"
    id="sale.menu_base_partner"
    groups="base.group_sale_salesman"
    sequence="20"/>

Avatar
Discard
Author

Thank you! But that does not work, I get the next error: AssertionError: The ID "sale.menu_base_partner" refers to an uninstalled module. In fact, the menu I want to change is "base.menu_base_partner" (I can see it trough the OpenERP interface).

Best Answer

if you want to override a id youn need to set the complete id module.id

Avatar
Discard
Best Answer

Do not forget insert into

<data noupdate="0">
<record model="ir.ui.menu" id="hr.menu_hr_root">
    <field name="name">HR</field>
<!-- in 11 version -->
    <field name="complete_name">HR</field>
</record>
</data>

to force the update of registry and CTRL+f5 in web browser to update the display name

Avatar
Discard
Best Answer

I had the same problem, after trying all the methods none worked. Finally I realized that there was a translation problem as the menuitem name term was already translated, therefor although the changes were made correctly they were not visible. Check out the tranlsation terms to check if your menu name is already there. The method I finally used was: 

<menuitem name="Sales"
id="account.menu_finance_receivables"
parent="account.menu_finance"
sequence="2"/>
Avatar
Discard
Best Answer

Using an SQL Manager I would open ir_ui_menu and ir_ui_menu_group_rel and delete all records related to this particular Menu. Then ammend my template and update

Try code below. Paying attantion to my bold text. The two must be exact. If you put base.menu_base_partner on the first one then the bottom one must also be base.menu_base_partner

<menuitem name="My new string"
    id="menu_base_partner"
    groups="base.group_sale_salesman"
    sequence="20"/>
<menuitem id="base.menu_sales" parent="menu_base_partner" name=
"My new string" sequence="1" />

Avatar
Discard

@Billiard, This is a wrong methodology. When you delete the record directly using SQL manager, the corresponding menus are removed. But when you update your database using -u all command, then you will have multiple menus (old+newly created menu)