Skip to Content
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
28771 Представления

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

Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
сент. 23
25410
0
мар. 15
3541
0
дек. 22
2580
2
дек. 19
14395
Id table odoo 10 Решено
3
нояб. 18
2629