跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. 让button在某些条件下隐藏

让button在某些条件下隐藏

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
4 帖子 2 发布者 6.8k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • J 离线
    J 离线
    jerry79
    写于 最后由 编辑
    #1

    当字段user_id等于当前登陆用户时,button不显示

    <br />&lt;group attrs=&quot;{&#039;invisible&#039;: [(&#039;user_id&#039;, &#039;=&#039;, uid) ] }&quot;&gt;<br />&lt;button name=&quot;case_return&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  states=&quot;open&quot; string=&quot;返回&quot; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  type=&quot;object&quot; icon=&quot;gtk-jump-to&quot; /&gt;<br />&lt;/group&gt;<br />
    



    经过测试,下面的代码也是成立的:

    <br />&lt;button name=&quot;change_deadline&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; states=&quot;draft,open&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string=&quot;变更&quot; type=&quot;object&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; icon=&quot;gtk-go-forward&quot;&nbsp; attrs=&quot;{&#039;invisible&#039;:[(&#039;user_id&#039;,&#039;!=&#039;,&#039;uid&#039;)]}&quot;/&gt;<br />
    


    上面的代码表示,虽然button在draft和open状态下应该显示,但是根据attrs的附加条件,如果user_id不是当前登陆用户的话,这个button还是不显示。

    1 条回复 最后回复
    0
    • mrshellyM 离线
      mrshellyM 离线
      mrshelly
      写于 最后由 编辑
      #2

      <button name="change_deadline"
                                  states="draft,open"
                                  string="变更" type="object"
                                  icon="gtk-go-forward"  attrs="{'invisible':[('user_id','!=',uid)]}"/>

      1 条回复 最后回复
      0
      • J 离线
        J 离线
        jerry79
        写于 最后由 编辑
        #3

        记录:
        6.1.1下会提示uid没有定义,官方buglist中此bug已经解决,但是截至今天(2012.6.28)下载的最新latest版本还是有次问题,只能手动修改,修改方法:

        <br />=== modified file &#039;openerp/osv/orm.py&#039;<br />--- openerp/osv/orm.py	2012-03-09 08:19:29 +0000<br />+++ openerp/osv/orm.py	2012-03-17 14:14:43 +0000<br />@@ -53,6 +53,7 @@<br /> import time<br /> import types<br /> from lxml import etree<br /> <br /> import fields<br /> import openerp<br />@@ -96,7 +97,7 @@<br /> # For non-tree views, the context shouldn&#039;t be given.<br /> def transfer_node_to_modifiers(node, modifiers, context=None, in_tree_view=False):<br />&nbsp; &nbsp;  if node.get(&#039;attrs&#039;):<br />-&nbsp; &nbsp; &nbsp; &nbsp; modifiers.update(eval(node.get(&#039;attrs&#039;)))<br />+&nbsp; &nbsp; &nbsp; &nbsp; modifiers.update(eval(node.get(&#039;attrs&#039;), context))<br /> <br />&nbsp; &nbsp;  if node.get(&#039;states&#039;):<br />&nbsp; &nbsp; &nbsp; &nbsp;  if &#039;invisible&#039; in modifiers and isinstance(modifiers&#91;&#039;invisible&#039;], list):<br />@@ -1706,6 +1707,13 @@<br /> <br />&nbsp; &nbsp; &nbsp; &nbsp;  # The view architeture overrides the python model.<br />&nbsp; &nbsp; &nbsp; &nbsp;  # Get the attrs before they are (possibly) deleted by check_group below<br />+&nbsp; &nbsp; &nbsp; &nbsp; context.update(<br />+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uid = user,<br />+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current_date = time.strftime(&#039;%Y-%m-%d&#039;),<br />+&nbsp; &nbsp; &nbsp; &nbsp; )<br />&nbsp; &nbsp; &nbsp; &nbsp;  transfer_node_to_modifiers(node, modifiers, context, in_tree_view)<br /> <br />&nbsp; &nbsp; &nbsp; &nbsp;  # TODO remove attrs couterpart in modifiers when invisible is true ?<br />
        


        链接;https://bugs.launchpad.net/openobject-server/+bug/920033

        1 条回复 最后回复
        0

        • 登录

        • 没有帐号? 注册

        • 登录或注册以进行搜索。
        • 第一个帖子
          最后一个帖子
        0
        • 版块
        • 标签
        • 热门
        • 用户
        • 群组