Odoo-特定用户的“隐藏"按钮 [英] Odoo - Hide button for specific user
问题描述
我正在使用odoo 10 enterpeise.我想向特定用户显示按钮,而不是向组显示按钮,因为一个组中会有很多用户,并且我只想在按钮下方显示具有拒绝/批准对象权限的按钮. 这是按钮
I am using odoo 10 enterpeise . I want to show buttons to specific users not to groups because there would be many users in a group and i want to only show below button who have the previlige to reject/approve a object. Here is button
<xpath expr="//sheet" position="before">
<header>
<button name="update_approve" attrs="{'invisible':[('first_approve', '=', uid)]}" string="Approve" type="object" class="oe_highlight"/>
<button name="update_reject" attrs="{'invisible':[('second_approve', '=', uid)]}" string="Reject" type="object" class="btn-danger"/>
</header>
</xpath>
我尝试使用uid
执行此操作,但uid在xml中不可用
I tried to do this using uid
but uid is not available in xml
first_approve
和second_approve
是我模型中的字段,基于这些字段,我仅希望向first_approve/second_approve
first_approve
and second_approve
are the fields in my model based on which i want to show button only to users which are assigned in first_approve/second_approve
推荐答案
我知道要在attrs中使用字段的一件事是必须以表格形式提及该字段.
我不知道如何在表单中获取用户ID的值.但是如果没有短暂
类似于uid
或user
的方式,您可以解决此问题,只需为res.users创建一个m2o字段即可.
使该字段计算具有store = False的字段.
One of the thing i know to use a field in attrs the field must be Mentionsed in the form.
i don't know how to get the value of the user id in the form. but if there is not a short
way like uid
or user
you can work arround this, just create a m2o field to res.users
make this field compute field with store = False.
# by default store = False this means the value of this field
# is always computed.
current_user = fields.Many2one('res.users', compute='_get_current_user')
@api.depends()
def _get_current_user(self):
for rec in self:
rec.current_user = self.env.user
,您可以在表单中使用此字段.
and you can use this field in your form.
<xpath expr="//sheet" position="before">
<header>
<!-- fin a good place for the field if i make the header look ugly -->
<!-- make invisible -->
<field name="current_user" invisible="1"/>
<!-- hope it work like this -->
<button name="update_approve" attrs="{'invisible':[('first_approve', '=', current_user)]}" string="Approve" type="object" class="oe_highlight"/>
<button name="update_reject" attrs="{'invisible':[('second_approve', '=', current_user)]}" string="Reject" type="object" class="btn-danger"/>
</header>
</xpath>
对不起,我的英语.
这篇关于Odoo-特定用户的“隐藏"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!