2

I have a menu named Portal Form. I want that menu to be visible for users with Portal group.

So far I have created users and assigned portal them Portal group. I have also added access rights of my model for the portal group. Everything as suggested in the previous question similar to mine, I have done followed all the solutions. Yet my custom menu is not visible to Portal users.

Can anybody tell me how is it achieved in Odoo 11?

Megha Sirisilla
  • 151
  • 2
  • 12

3 Answers3

1

Let us start from scratch by creating a toy module called my_module.

First, we need to create a model. The file addons/my_module/models/models.py contains:



    from odoo import api, fields, models, tools, _

    class Books(models.Model): 
      _name = 'my_module.books'

      title = fields.Char(string='Title')
      author = fields.Char(string='Author')

Now, we are in position to create menus, actions and views. The file addons/my_module/views/views.xml contains:



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

        <!-- Top menu item -->
        <menuitem name="My top menu" id="my_module.menu_root"/>

        <!-- menu categories -->
        <menuitem name="My left-side menu" id="my_module.menu_left" parent="my_module.menu_root"/>    

        <!-- Model Books: views, actions and menus -->

        <!-- explicit tree view definition -->
        <record model="ir.ui.view" id="my_module.books_view_tree">
          <field name="name">My books - List view</field>
          <field name="model">my_module.books</field>
          <field name="arch" type="xml">
            <tree>
          <field name="title"/>
          <field name="author"/>
            </tree>
          </field>
       </record>

       <!-- explicit form view definition -->
        <record model="ir.ui.view" id="my_module.books_view_form">
          <field name="name">My books - Form view</field>
          <field name="model">my_module.books</field>
          <field name="arch" type="xml">
        <form string="My books">
          <sheet>
            <group>
              <field name="title"/>
              <field name="author"/>
            </group>
          </sheet>
        </form>
          </field>
        </record>

        <!-- action opening views for this model -->
        <record model="ir.actions.act_window" id="my_module.books_action_window">
          <field name="name">My Books - Window action</field>
          <field name="res_model">my_module.books</field>
          <field name="view_mode">tree,form</field>
        </record>

        <!-- menu for the above action -->
        <menuitem name="Books" id="my_module.menu_books" parent="my_module.menu_left" action="my_module.books_action_window" sequence="6" />

      </data>
    </openerp>

Then, we need a manifesto. The file addons/my_module/__manifest__.py contains:


    {
        'name': "my_module",
        'summary': "Answer to Stack Overflow Question 52733625",
        'description': "Answer to Stack Overflow Question 52733625",
        'author': "Adán Cortés Medina",
        'website': "http://www.linkedin.com/in/1acme",

        # Categories can be used to filter modules in modules listing
        # Check https://github.com/odoo/odoo/blob/9.0/openerp/addons/base/module/module_data.xml
        # for the full list
        'category': 'Uncategorized',
        'version': '0.1',

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

        # always loaded
        'data': [
            'views/views.xml',
            #'security/ir.model.access.csv',
        ],
        # only loaded in demonstration mode
        'demo': [
            #'demo/demo.xml',
        ],
    }

At this point, you most likely want to create a new database and load the module. There will be a menu on top named My top menu, then there will be a label on the left reading My left-side menu and beneath there will be a menu reading Books which, when you click on it, the list view for the books model will be shown. Also, when you click on the Create button, you will be shown the form view for the said model.

Once that it is tested, let us add security. First, go to the __manifest__.py file and uncomment #'security/ir.model.access.csv', by removing the leading #. Then create addons/my_module/security/ir.model.access.csv with the following contents:


"id","name","model_id/id","group_id/id","perm_read","perm_write","perm_create","perm_unlink"
"access_my_module_books","my_module.books","my_module.model_my_module_books","base.group_portal","True","True","True","True"

Restart Odoo, just to be on the safe side and then go to the Apps menu and reload your module by clicking first on its card and then on the Upgrade button.

Now, enter to debug mode by adding debug just before the # (the URL should be like http://example.com:8096/web?debug#...) and create a user while making sure it belongs to the portal group (Other Extra Rights/Portal must be ticked). Click on the Save button. Look for the Action drop-down menu on the top of the form and select Change password. Write a password, click on Save.

Then open a new incognito window (to be able to have two Odoo accounts simultaneously open) and log in with the user you just created. The Books menu should be shown there.

Finally, create a new user not belonging to the Portal group, log in with that user and check that the Books menu won't show.

You can download the aforementioned toy module from https://github.com/AdanCortes/stackoverflow/tree/q52733625

Adan Cortes
  • 1,058
  • 8
  • 13
  • Hey..thank you for such a detailed answer. Just to check if the module given in the link above works with my test addons or not I installed it after downloading. So when I login with a demo user, I'm not able to see the Books menu. Neither are regular users. Only the admin can see it. – Megha Sirisilla Oct 23 '18 at 07:08
  • Anytime, Meg. Usually, regular users don't belong to the `portal` group but they should be able to see the menu if you manually add them by editing the `portal` group members. If something goes wrong, drop me a line. – Adan Cortes Oct 30 '18 at 23:30
0

In Odoo 11 the portal users will access to a website like panel to be able to access to separated info showed by custom templates. The portal view could be accessed at the url /my/home like http://example.com/my/home.

You could see an example at(purchase orders at the user portal):

https://github.com/odoo/odoo/blob/078b31dc7f67f3893bcbe5a3b76936490add0e38/addons/purchase/views/portal_templates.xml

aekis.dev
  • 2,626
  • 1
  • 12
  • 19
0

XML code to create the template ie, the new menu

<template id="your_id" name="your name" inherit_id="portal.portal_my_home" priority="21">
    <xpath expr="//ul[hasclass('o_portal_docs')]" position="inside">
        <li class="list-group-item">
            <span class="badge" t-esc="quotation_count"/>
            <a href="/my/records/portal"> Portal Form</a>
        </li>
    </xpath>
</template>

The python code is below and it should be in the controller

class CustomerPortal(CustomerPortal):

    @http.route(['/my/records/portal', '/my/quotes/page/<int:page>'], type='http', auth="user", website=True)
    def portal_my_records(self, page=1, date_begin=None, date_end=None, sortby=None, **kw):     
        print("IN PYTHON CONTROLLER")
        data={}
        return request.render("module_name.template_name", data)

By this, a new menu called Portal Form is created and if you click on that menu the above python function will work. And if you want to call another template you can just type the name of that template in return of that function and data is the values that can be used in the template.

If you are using other versions of odoo there will be the change in the inherit_id of the template.

Hope you understood. Thankyou