콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
30173 화면

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
26737
0
3월 15
4250
0
12월 22
3181
2
12월 19
15331
Id table odoo 10 해결 완료
3
11월 18
3022