我要添加一個域用於在表格視圖,這將在下面給定按鈕的屬性ATTRS濾波當前用戶ID:如何在Odoo的窗體視圖中獲取當前用戶標識(uid)?
<button name="my_name" attrs="{'invisible': [('my_field', '!=', uid)]}" />
UID是沒有定義是錯誤。我試着用user.id,user_id,這也給出了同樣的錯誤。請幫我
我要添加一個域用於在表格視圖,這將在下面給定按鈕的屬性ATTRS濾波當前用戶ID:如何在Odoo的窗體視圖中獲取當前用戶標識(uid)?
<button name="my_name" attrs="{'invisible': [('my_field', '!=', uid)]}" />
UID是沒有定義是錯誤。我試着用user.id,user_id,這也給出了同樣的錯誤。請幫我
在視圖模型中,有一個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下載
uid僅用於域內,不在attrs內。
這裏是一個解決方法:
<button name="btn_name" type="object" string="string" groups="module.group_name"/>
嘗試這種方式
感謝您的關注和時間。我解決了它,並在答案部分更新了它。 – manuthalasseril
尼斯解。但在我的情況下,我有一個要求在表單視圖上使用uid的要求。因爲我想隱藏用戶之間的按鈕,即使它們屬於同一組。 – manuthalasseril