- Odoo 11 Development Cookbook(Second Edition)
- Holger Brunn Alexandre Fayolle
- 114字
- 2021-06-25 22:48:43
How to do it...
The security rules we want to add in this recipe are as follows:
- Everyone will be able to read library book records
- A new group of users called "Librarians" will have the right to create, read, update, and delete book records
To implement this, you need to perform the following steps:
- Create a file called security/groups.xml with the following content:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="group_librarian" model="res.groups">
<field name="name">Librarians</field>
</record>
</odoo>
- Add a file called security/ir.model.access.csv with the following content:
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
acl_book,library.book default,model_library_book,,1,0,0,0
acl_book_librarian,library.book_librarian,model_library_book,group_librarian,1,1,1,1
- Add both files in the data entry of __manifest__.py:
# ...
'data': [
'security/groups.xml',
'views/library_book.xml',
'security/ir.model.access.csv',
],
# ...
The newly defined security rules will be in place once you update the addon in your instance.