How to do it...

To add new access security groups to a module, perform the following steps:

  1. Ensure that the __manifest__.py add-on module manifest has the category key defined:
    'category': 'Library', 
  1. Add the new security/groups.xml file to the manifest data key:
    'data': [ 
        'security/groups.xml', 
        'views/library_book.xml', 
    ],
  1. Add the new XML file for the data records at security/library_security.xml, starting with an empty structure:
<?xml version="1.0" encoding="utf-8"?> 
<odoo> 
    <!--  Data records go here --> 
</odoo> 
  1. Add the record tags for the two new groups inside the data XML element:
<record id="group_library_user" model="res.groups">
<field name="name">User</field>
<field name="category_id" ref="base.module_category_library"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>

<record id="group_library_librarian" model="res.groups">
<field name="name">Librarians</field>
<field name="category_id" ref="base.module_category_library"/>
<field name="implied_ids" eval="[(4, ref('group_library_user'))]"/>
<field name="users" eval="[(4, ref('base.user_admin'))]"/>
</record>

If we upgrade the add-on module, these two records will be loaded. In order to see these groups in the UI, you need to activate developer mode. You'll then be able to see them through the Settings|Users|Groups menu option.

In Odoo v12, the default security for newly added models works differently to previous models. In v12, if you are adding a new model, the admin user doesn't get access rights for that model. This means that the menus and views that have been added for that model are not visible to the admin user. In order to display it, you need to add access rules for that model, which is coming in the Adding security access to models recipe. By the way, you can access newly added models through the superuser; to learn more about it, please refer to the Accessing Odoo as a superuser recipe from Chapter 4, Creating Odoo Add-On Modules.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset