跳至内容
菜单
此问题已终结
2 回复
29801 查看

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
形象
丢弃
最佳答案

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
形象
丢弃
编写者

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

最佳答案

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',
....
]

形象
丢弃
相关帖文 回复 查看 活动
2
9月 23
26366
0
3月 15
4043
0
12月 22
3025
2
12月 19
15121
3
11月 18
2953