我想添加一个域,用于在"表单视图"中的" attrs属性"中过滤当前用户ID,这是以下内容:
<button name="my_name" attrs="{'invisible': [('my_field', '!=', uid)]}" />
未定义的是错误。我尝试使用user.id,user_id。,这也给出了相同的错误。请帮助我
uid仅在域内而不是在attrs中使用。
这是一个解决方法:
- 创建一个组
- 将用户分配给组
- 将小组分配到按钮。
<button name="btn_name" type="object" string="string" groups="module.group_name"/>
尝试这种方式
- 在复苏者中创建一个布尔字段。
- 在您的表单类中创建一个布尔类型计算字段。
标记计算字段如果在复苏者中的布尔字段为真。
如果self.env ['res.users']。浏览(self.env.uid).show_button:
&nbsp; self.computefield = true - 在按钮上使用attrs中的计算字段
在视图模型中,有一个python eval正在登记属性,这就是为什么我们会遇到此错误的原因。为了克服这一点,我们必须超越名为" trassion_node_to_modifiers "的功能。代码如下:
def transfer_node_to_modifiers(node, modifiers, context=None, in_tree_view=False):
if node.get('attrs'):
#If you want, add more conditions here
if ', uid' in node.get('attrs'):
user_id = str(context.get('uid', 1))
user_id = ', ' + user_id
attrs = node.get('attrs')
attrs = attrs.replace(', uid', user_id)
node.set('attrs', attrs)
modifiers.update(eval(node.get('attrs')))
if node.get('states'):
if 'invisible' in modifiers and isinstance(modifiers['invisible'], list):
# TODO combine with AND or OR, use implicit AND for now.
modifiers['invisible'].append(('state', 'not in', node.get('states').split(',')))
else:
modifiers['invisible'] = [('state', 'not in', node.get('states').split(','))]
for a in ('invisible', 'readonly', 'required'):
if node.get(a):
v = bool(eval(node.get(a), {'context': context or {}}))
if in_tree_view and a == 'invisible':
# Invisible in a tree view has a specific meaning, make it a
# new key in the modifiers attribute.
modifiers['tree_invisible'] = v
elif v or (a not in modifiers or not isinstance(modifiers[a], list)):
# Don't set the attribute to False if a dynamic value was
# provided (i.e. a domain from attrs or states).
modifiers[a] = v
调用UID与问题相同
<button name="my_name" attrs="{'invisible': [('my_field', '!=', uid)]}" />
我为此创建了一个补丁。如果有人需要,请从此处下载