gpt4 book ai didi

python - Odoo - 为特定用户隐藏按钮

转载 作者:太空狗 更新时间:2023-10-29 18:34:50 25 4
gpt4 key购买 nike

我正在使用 odoo 10 企业版。我想向特定用户显示按钮而不是组,因为组中会有很多用户,我只想在下面显示具有拒绝/批准对象权限的按钮。这是按钮

<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 中不可用

first_approvesecond_approve 是我模型中的字段,我想根据这些字段仅向在 first_approve/second_approve 中分配的用户显示按钮>

最佳答案

我知道在 attrs 中使用字段的一件事是必须在表单中提及该字段。 我不知道如何在表单中获取用户 ID 的值。但如果没有短路 像 uiduser 你可以解决这个问题,只需创建一个 m2o 字段到 res.users 使用 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

您可以在表单中使用此字段。

    <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>

对不起我的英语。

关于python - Odoo - 为特定用户隐藏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44726756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com