请问下用代码如何设置自己的模块访问权限??
-
我是模仿hr模块中的XML文件(hr_security.xml),可是有的地方看不懂啊,以下是文件的内容:
<openerp>
<data noupdate="0">
<record model="res.groups" id="base.group_user">
<field name="comment">user will be able to manage his own human resources stuff (leave request, timesheets, ...), if he is linked to an employee in the system.</field>
</record>
<record id="base.group_hr_user" model="res.groups">
<field name="name">Officer</field>
<field name="category_id" ref="base.module_category_human_resources"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
<field name="comment">the user will be able to approve document created by employees.</field>
</record>
<record id="base.group_hr_manager" model="res.groups">
<field name="name">Manager</field>
<field name="comment">the user will have an access to the human resources configuration as well as statistic reports.</field>
<field name="category_id" ref="base.module_category_human_resources"/>
<field name="implied_ids" eval="[(4, ref('base.group_hr_user'))]"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
</data>
<data noupdate="1">
<record id="hr_dept_comp_rule" model="ir.rule">
<field name="name">Department multi company rule</field>
<field model="ir.model" name="model_id" ref="model_hr_department"/>
<field eval="True" name="global"/>
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
</record>
<record id="hr_job_comp_rule" model="ir.rule">
<field name="name">Job multi company rule</field>
<field model="ir.model" name="model_id" ref="model_hr_job"/>
<field eval="True" name="global"/>
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
</record>
</data>
</openerp>
我看不懂ref和eval的意思,想来想去还是没想通... eval="[(4, ref('base.group_hr_user'))]"这个是感觉最诡异的..
有哪位高人能解释解释吗? -
ref 是把 xml_id 转成数据库里的 res_id,
eval 是把字符串转成python表达式
[(4, ref('base.group_hr_user'))] 这个是openerp的特殊用法,见 http://git.oschina.net/osbzr/openerp_7_osbzr/blob/master/openerp7/openerp/osv/fields.py#L1249 -
res_id是什么意思呢??
我可不可以这么认为 对于openerp的XML文件中的每一个<record>都是对应存储在数据库中的一条记录?
比如
<record model="res.groups" id="base.group_user">
<field name="comment">user will be able to manage his own human resources stuff (leave request, timesheets, ...), if he is linked to an employee in the system.</field>
</record>
这个表示的是 在res.groups表中有一条记录,它的字段"comment"为user will be able to manage his own human resources stuff (leave request, timesheets, ...), if he is linked to an employee in the system.可是这么认为的话,这条记录就只有comment字段有值吗??