让button在某些条件下隐藏
-
当字段user_id等于当前登陆用户时,button不显示
<br /><group attrs="{'invisible': [('user_id', '=', uid) ] }"><br /><button name="case_return"<br /> states="open" string="返回" <br /> type="object" icon="gtk-jump-to" /><br /></group><br />
经过测试,下面的代码也是成立的:<br /><button name="change_deadline"<br /> states="draft,open"<br /> string="变更" type="object"<br /> icon="gtk-go-forward" attrs="{'invisible':[('user_id','!=','uid')]}"/><br />
上面的代码表示,虽然button在draft和open状态下应该显示,但是根据attrs的附加条件,如果user_id不是当前登陆用户的话,这个button还是不显示。 -
记录:
6.1.1下会提示uid没有定义,官方buglist中此bug已经解决,但是截至今天(2012.6.28)下载的最新latest版本还是有次问题,只能手动修改,修改方法:<br />=== modified file 'openerp/osv/orm.py'<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't be given.<br /> def transfer_node_to_modifiers(node, modifiers, context=None, in_tree_view=False):<br /> if node.get('attrs'):<br />- modifiers.update(eval(node.get('attrs')))<br />+ modifiers.update(eval(node.get('attrs'), context))<br /> <br /> if node.get('states'):<br /> if 'invisible' in modifiers and isinstance(modifiers['invisible'], list):<br />@@ -1706,6 +1707,13 @@<br /> <br /> # The view architeture overrides the python model.<br /> # Get the attrs before they are (possibly) deleted by check_group below<br />+ context.update(<br />+ uid = user,<br />+ current_date = time.strftime('%Y-%m-%d'),<br />+ )<br /> transfer_node_to_modifiers(node, modifiers, context, in_tree_view)<br /> <br /> # TODO remove attrs couterpart in modifiers when invisible is true ?<br />