Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

让button在某些条件下隐藏



  • 当字段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还是不显示。



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



  • 记录:
    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


Log in to reply