2017-09-24 94 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

相關問題