2017-09-24 90 views

回答

1

在视图模型中,有一个python eval正在执行attrs属性,这就是为什么我们得到这个错误。为了克服这个问题,我们必须重写名为“transfer_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)]}" /> 

我创建了一个补丁这一点。如果有人需要,请从here下载

1

uid仅用于域内,不在attrs内。

这里是一个解决方法:

  1. 创建组
  2. 将用户分配到组
  3. 分配组按钮。
<button name="btn_name" type="object" string="string" groups="module.group_name"/> 
+0

尼斯解。但在我的情况下,我有一个要求在表单视图上使用uid的要求。因为我想隐藏用户之间的按钮,即使它们属于同一组。 – manuthalasseril

1

尝试这种方式

  1. 在ResUsers创建一个布尔字段。
  2. 在窗体的类中创建一个布尔类型计算字段。
    mark compute field如果ResUsers中的布尔型字段为True,则为真。
    如果self.env [ 'res.users']浏览(self.env.uid).show_button:
        self.computefield在ATTRS =真
  3. 使用计算字段上按钮
+0

感谢您的关注和时间。我解决了它,并在答案部分更新了它。 – manuthalasseril

相关问题