İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
916 Görünümler

Version: Odoo 17.0

I've been playing with odoo, and i want to add a link to a menu dropdown, i would like to add it to the Product menu in the inventory module. 


After looking through the documentation, and looking at the code of the already present button  i have created a module and installed it into odoo, i have tried with the following code in views/menus.xml, however no button is added to the menu.
This is my menu/views.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<menuitem id="custom_menu_item_stock"
name="Test"
parent="stock.menu_stock_inventory_control"
action="custom_action_url"
sequence="10"/>
<record id="custom_action_url" model="ir.actions.act_url">
<field name="name">Custom Button URL</field>
<field name="url">https://www.example.com</field>
<field name="target">new</field>
</record>
</data>
</odoo>


and this is my __manifest__.py

{
    'name': "my_module",

    'summary': """
        Short (1 phrase/line) summary of the module's purpose, used as
        subtitle on modules listing or """,

    'description': """
        Long description of module's purpose
    """,

    'author': "My Company",
    'website': "http://www.yourcompany.com",

        'category': 'Uncategorized',
    'version': '0.1',

    # any module necessary for this one to work correctly
    'depends': [
        'base',
        'stock'
    ],

    # always loaded
    'data': [
        'views/menus.xml',
    ],
    # only loaded in demonstration mode
    'demo': [

    ],
   
}
Avatar
Vazgeç
Üretici En İyi Yanıt

Just as you both said, reversing the order so the action is declared before the button fixes the issue, thanks!

Avatar
Vazgeç
En İyi Yanıt

I tried your code and it work fine.
Maybe you need to put tag record​before tag menuitem​, and then try to upgrade your module again.

Avatar
Vazgeç
En İyi Yanıt

Hi,


Your approach to adding a custom menu item to the "Product" menu in the Inventory module looks almost correct. However, ensure the ir.actions.act_url record is defined before you reference it in the tag. This ensures the action exists when the menu item is being created.

For example use the following code:

<?xml version="1.0" encoding="utf-8"?>
<odoo>

 <data>
        <!-- Define the custom action URL -->
        <record id="custom_action_url" model="ir.actions.act_url">
            <field name="name">Custom Button URL</field>
<field name="url">https://www.example.com" target="_blank" data-saferedirecturl="https://www.example.com</field>
 " rel="ugc">https://www.google.com/url?q=https://www.example.com&source=gmail&ust=1727841619164000&usg=AOvVaw00Za-dJNBfBk9DVGbZdVnn">https://www.example.com</field>
            <field name="target">new</field>
        </record>

        <!-- Add a menu item under the Products menu in Inventory module -->
        <menuitem id="custom_menu_item_stock"
                  name="Test"
parent="stock.menu_stock_inventory_control"
                  action="custom_action_url"
                  sequence="10"/>
    </data>

</odoo>

Regards

Avatar
Vazgeç