【问题标题】:How to hide a workflow button based on user in openerp 7?如何在 openerp 7 中隐藏基于用户的工作流按钮?
【发布时间】:2014-06-27 09:56:07
【问题描述】:

有没有办法根据登录的用户隐藏工作流按钮?

我正在开发一个 OpenERP 7.0 模块,并且在此过程的某个阶段,用户可以承担责任。 我试过这个<button name="take_request" string="Take request" help="Take this request to your responsability" attrs="{'invisible': ['|', ('state','!=','treatment'),('owner','=',user.id)]}" />(就像我在域规则中所做的那样),但我收到以下错误:

NameError: name 'user' is not defined

如果我尝试<button name="take_request" string="Take request" help="Take this request to your responsability" attrs="{'invisible': ['|', ('state','!=','treatment'),('owner','=','user.id')]}" />(引号内带有用户.id)我没有收到错误,但它没有隐藏按钮。

提前致谢!

【问题讨论】:

    标签: button attributes workflow hide openerp


    【解决方案1】:

    我终于解决了,它工作正常。我在我的对象中使用了一个 field.function 在我的按钮的不可见属性中使用了这个字段。相关代码留在这里供以后参考。

    在我的 py 中,创建了一个函数来检查我是否对任何请求负责,并在我的对象上添加了一个 field.function:

        def _check_ami_responsible(self, cr, uid, ids, field_name, arg, context):
            """ Checks if user is responsible for this request
            @return: Dictionary of values
            """
            res = {}
            for req in self.browse(cr, uid, ids, context=context):
                if req.responsible_name.id == uid:
                    res[req.id] = True
                else:
                    res[req.id] = False
            return res
    
        (...)
    
       _columns={
            (....)
            'ami_responsible': fields.function(_check_ami_responsible, type="boolean", obj="generic.request", method=True),
        }
    

    然后在我看来,我在按钮上添加了条件 ('ami_responsible', '=', False) 以在不负责该请求时将其隐藏。

    <button name="confirm_request" class="oe_highlight" string="Confirm Request" type="workflow" attrs="{'invisible': ['|',('ami_responsible', '=', False), '|',('state','!=', 'submitted'), ('needs_reformulation', '=', True)]}" />
    

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      尝试使用uid 而不是user.id。在xml 中你不能传递'user' 这是一个res.user 对象。但是你可以传递active_id、uid、parent。如果它有父视图、上下文等

      【讨论】:

      • 使用 uid(不带引号)我得到相同的“NameError: name 'uid' is not defined”并且带引号它不会过滤我想要的 wath。尝试使用域作为按钮的属性,但它也不起作用。使用 field.function boolean 解决了它(我将把答案留给有同样问题的其他用户)
      猜你喜欢
      • 1970-01-01
      • 2012-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多