最近在写权限,记录下权限问题
- 如果想要继承原生的,一般都会加到下面来,因为加的这个没有上下级关系
- 单独的组
类似这种单独的组是要有单独的 model=“ir.module.category” 的数据,下面的model="res.groups"类别关联上面的就ok
类似代码如下:
<record model="ir.module.category" id="module_category_wg_production_function">
<field name="name">销售功能组</field>
<field name="description">销售功能组</field>
<field name="sequence">20</field>
</record>
<record id="wg_sale_product_pricelist_query" model="res.groups">
<field name="name">价格表查询(仅自己)</field>
<field name="category_id" ref="module_category_wg_production_function"/>
</record>
<record id="wg_sale_unit_cost" model="res.groups">
<field name="name">成本单价</field>
<field name="category_id" ref="module_category_wg_production_function"/></record>
下面的model="res.groups"的category_id字段关联 model=“ir.module.category” 的 id
module_category_wg_production_function
- 只能查看自己的
<record id="wg_sale_product_pricelist_query" model="res.groups">
<field name="name">价格表查询(仅自己)</field>
<field name="category_id" ref="module_category_wg_production_function"/>
</record>
<record id="wg_sale_product_pricelist_self" model="ir.rule">
<field name="name">价格表查询(仅自己)</field>
<field ref="product.model_product_pricelist" name="model_id"/>
<field name="domain_force">[('create_uid','=',user.id)]</field>
<field name="global" eval="True"/>
<field name="groups" eval="[(4, ref('wg_sale_product_pricelist_query'))]"/>
</record>
- 给原生菜单加权限
<record id="sale.menu_sale_order" model="ir.ui.menu">
<field name="groups_id"
eval="[(4, ref('group_wg_production_salesperson')),
(4, ref('group_wg_department_manager')), (4,ref('sales_team.group_sale_manager'))]"/>
</record>
- 隐藏原生菜单
<record id="sale.menu_sale_invoicing" model="ir.ui.menu">
<field name="active" eval="False"/>
</record>
-
对某个字段无权限时只读
加个布尔字段,来判断当前的用户是否在这个权限组里,是的话变为True,否则False
@api.depends(‘edit_whether’)
def _compute_edit_whether(self):
if self.user_has_groups(‘sales_team.group_sale_manager’):
self.edit_whether = True
else:
self.edit_whether = False -
如果写的权限无效,不起作用
这种情况一般是权限冲突了,也就是说有个权限大于你的权限
一般去 第二个按钮(Access Rights)里面的视图去找冲突点,筛选对这个模型的,然后对大于你的权限的去掉
大部分在这里的权限大,先去这个里面找对应的。
此文章仅代表个人意见