问题
<record model="ir.rule" id="stock_inventory_comp_rule">
<field name="name">Inventory multi-company</field>
<field name="model_id" ref="model_stock_inventory" />
<field name="global" eval="True" />
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]
</field>
</record>
I'm confused with above code fragment in security.xml files which is mean by below tags.?
id="stock_inventory_comp_rule"
means of this line and where its tag with.or is it only for save & keep for identify records by id purpose.?
<field name="name">Inventory multi-company</field>
mean by this line.is this only use for display purpose.?
<field name="model_id" ref="model_stock_inventory" />
which one is mean by model_stock_inventory and what is the usage of this .?
<field name="global" eval="True" />
why this one set global True.?if we set it as False then what will the expected result.?
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]
here shows like domain filter in fields.? is this criteria set to above mentioned model class.?what is the usage of this fragment.?
回答1:
ir.rule is used with groups, like in sale order you want a case that every user just see his own record not other user sale order, so you make a record rule in ir.rule to stop other user to see each other sale order, and assign this rule to some group when you assing this group to user it automatically apply this rule
Example
<record id="sale_order_user_rule" model="ir.rule">
<field name="name">Quotations/Sale Orders</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="domain_force">[('user_id','in',[user.id])]</field>
<field name="groups" eval="[(4, ref('group_purcase_manager'))]"/>
<field eval="1" name="perm_unlink"/>
<field eval="1" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="1" name="perm_create"/>
</record>
As you see in example i have created a rule to restrict other user to see each other record and assign this rule to group purchase manager, you can restrict user access righs also like read, write, create, delete etc by this rule
Like in your example you make a rule to see company and his child reocrd all record global means it rule apply to all with out assinging to any group
来源:https://stackoverflow.com/questions/16234383/openerp-ir-rule-records-in-security-xml