Skip to Content
Menu
This question has been flagged
2 Replies
27221 Views

I want to create a new group user and give it a access right, but I have a problem with csv file

_openerp_

 'data': [
             'security/ir.model.access.csv', 'security/asinhvien_security.xml',
        ... 
my model
class SinhvienList(osv.osv):
...


security/asinhvien_security.xml:

<data>
	<record model="ir.module.category" id="asinhvien_group_category">
            <field name="name">Tài khoản</field>
            <field name="description">....</field>
    	</record>
    	
    	<record id="asinhvien_sinhvien_group" model="res.groups"> 
            <field name="name">Sinh viên</field>
            <field name="category_id" ref="asinhvien_group_category"/>
        </record>
    	
    	<record id="asinhvien_giangvien_group" model="res.groups"> 
            <field name="name">Giảng viên</field>
            <field name="category_id" ref="asinhvien_group_category"/>
        </record>

    </data>	
 security/ir.model.access.csv
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_asinhvien_giangvien,access.asinhvien.giangvien,model_SinhvienList,asinhvien_giangvien_group,1,1,1,1
access_asinhvien_sinhvien,access.asinhvien.sinhvien,model_SinhvienList,asinhvien_sinhvien_group,1,0,0,0

But when I run the sever and localhost, the problem occur :
 
Exception: Module loading asinhvien failed: file asinhvien\security/ir.model.access.csv could not be processed:
 Line 1 : No matching record found for external id 'model_SinhvienList' in field 'Object'
Thanks for any help
Avatar
Discard
Best Answer

Hai Tai,

class SinhvienList(osv.osv):
...

In this you have used the class name in the CSV,  you have to use model name instead of the class name,

class SinhvienList(osv.osv):
_name = 'test_model_name
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_asinhvien_giangvien,access.asinhvien.giangvien,model_test_model_name,asinhvien_giangvien_group,1,1,1,1
access_asinhvien_sinhvien,access.asinhvien.sinhvien,model_test_model_name,asinhvien_sinhvien_group,1,0,0,0
Avatar
Discard
Author

tks, it works! But why i readed some documentation which require the name of class?

Best Answer

If the model is not defined in the same module of the ir.model.access.csv ,  then you need to specify the module when defining the security line,

eg:

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_asinhvien_giangvien,access.asinhvien.giangvien,module_name.model_model_name,asinhvien_giangvien_group,1,1,1,1
access_asinhvien_sinhvien,access.asinhvien.sinhvien,module_name.model_model_name,asinhvien_sinhvien_group,1,0,0,0

Note:

While giving access rights just make sure you keep csv file below the security.xml. It is because when Csv file loads it won't be able to find the user groups specified in the csv because the security.xml which have the group defenitions are called second.

so in _openerp_.py:

'data': [ 
            'security/asinhvien_security.xml',
            'security/ir.model.access.csv',
....
]

Avatar
Discard
Related Posts Replies Views Activity
2
Sep 23
23926
0
Mar 15
3140
0
Dec 22
2078
2
Dec 19
13447
3
Nov 18
2166