Custom Menu for New Module – Odoo

Thanks to Odoo’s hugely flexible architecture, all too often, we find ourselves programming new modules for business processes. In a recent project for developing new features to accomodate a business model for a client, where an existing Odoo-Module had to be extended, and at the same time a new module had to be developed, we faced challenges in exposing new menu-items to non-admin users.

Actually its straight forward when the module is extending some existing group or model. The real pain comes when we have completely different module. e.g. we had categories module which was extending res_parterners_category hence was showing in the sidebar-menu without a problem. But for a complete new content-management (CMS) module, called advertiseprofile, written from scratch, the menus wouldn’t show!

To solve this we tried every group, permissions etc. at first. The solution however was to include a proper security model for our new module, starting from the security folder and files which got created during scaffolding process.

To get the process started modify 3 files:

__openerp__.py

security/<modulename>_security.xml
 security/ir.model.access.csv

Taking example of our module – advertiseprofile below is the code snippets.

__openerp__.py

Add your security file details in “data” attribute.

e.g:
 'data' : [
      'security/advertiseprofile_security.xml',
      'security/ir.model.access.csv',
      'views/adprofiles.xml',
      'views/adstatinfo.xml'
 ]

security/_security.xml

Add below lines to this file, making sure to change the values as per your module information:

<?xml version="1.0"?>
<openerp>
    <data>
        <record model="ir.module.category" id="advertiseprofile_category">
            <field name="name">Advertiseprofile</field>
            <field name="sequence">16</field>
        </record>
        <record model="res.groups" id="group_advertiseprofile_user">
            <field name="name">Advertiseprofile User</field>
            <field name="category_id"  ref="advertiseprofile_category"/>
        </record>    
        <record model="res.groups" id="group_advertiseprofile_manager">
            <field name="name">Advertiseprofile Manager</field>
            <field name="implied_ids" eval="[(4, ref('advertiseprofile.group_advertiseprofile_user'))]"/>
            <field name="category_id"  ref="advertiseprofile_category"/>
        </record>
        
        <!-- Record Rule.. -->    
        <record model="ir.rule" id="rule_advertiseprofile_adprofiles">
            <field name="name">Advertiseprofile Profiles</field>
            <field name="model_id" ref="model_advertiseprofile_adprofiles"/>
            <field name="domain_force"></field>
            <field name="groups" eval="[(4, ref('group_advertiseprofile_user'))]"/>
        </record>
        
        <record model="ir.rule" id="rule_advertiseprofile_adstatinfo">
            <field name="name">Advertiseprofile Statistics</field>
            <field name="model_id" ref="model_advertiseprofile_adstatinfo"/>
            <field name="domain_force"></field>
            <field name="groups" eval="[(4, ref('group_advertiseprofile_user'))]"/>
        </record>
    </data>
</openerp>

​security/ir.model.access.csv

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
 access_advertiseprofile_adprofiles_manager,advertiseprofile.adprofiles.manager,model_advertiseprofile_adprofiles,group_advertiseprofile_manager,1,1,1,1
 access_advertiseprofile_adprofiles_user,advertiseprofile.adprofiles.user,model_advertiseprofile_adprofiles,group_advertiseprofile_user,1,0,0,0
 access_advertiseprofile_adstatinfo_manager,advertiseprofile.adstatinfo,model_advertiseprofile_adstatinfo,group_advertiseprofile_manager,1,1,1,1
 access_advertiseprofile_adstatinfo_user,advertiseprofile.adstatinfo,model_advertiseprofile_adstatinfo,group_advertiseprofile_user,1,1,0,0​

​Once your module is configured properly then, you will see new “Application”​ of your module. See custom-module-application.png.
Similarly it creates groups under GROUPs. See custom-module-group.png

nebiz logo

Industriestraße 24b D-70565 Stuttgart – Deutschland

Tel. +49-711-7947-2394 Email. beratung@nebiz.de

© 2019 NEBIZ®

Über uns

NEBIZ® ist Ihr Partner für die Entwicklung erfolgreicher e-Commerce Lösungen. Wir liefern Ihnen leistungsfähige Technik und sinnvolle Beratung, damit Sie sich ganz auf Ihr Kerngeschäft konzentrieren können.

Neben unserem Umsetzung- und Programmierung-Know-how stehen wir Ihnen mit Online Marketing zur Seite.