2015-06-25 79 views
-1

我的OpenERP 6.0創建的模塊功能,即OpenERP的6.0不支持相同的代碼的OpenERP 7的問題,這是函數創建:如果有一個人能幫助我解決這個問題:創建的OpenERP 6.0

def create(self, cr, uid, vals, context=None): 
    if context is None: 
     context = {} 
    if vals['teacher_id']: 
     teacher=self.pool.get("res.partner").browse(cr,uid,vals['teacher_id'],context) 
     teacher.attendee=True 
    if vals['etudiant_ids'][0][2]: 
     for etudiant in self.pool.get("res.partner").browse(cr,uid,vals['etudiant_ids'][0][2],context): 
      etudiant.attendee=True 
    return super(attendee, self).create(cr, uid, vals, context=context) 

問題是在 「如果瓦爾斯[ 'etudiant_ids'] [0] [2]:」

if vals['etudiant_ids'][0][2]: 
TypeError: 'bool' object has no attribute '__getitem__' 
+0

請使用代碼塊和正確的縮進,特別是因爲縮進在語法上與python相關。我試圖修復它,請檢查它是否正確。 – Dakkaron

回答

1

上述錯誤出現,當你正在訪問一個字典,其鍵是找不到的。 更好的調試方法是,使用print語句檢查值 print vals ['etudiant_ids'], print vals ['etudiant_ids'] [0], print vals ['etudiant_ids'] [0] [2] , ,你可以知道密鑰沒有取到的位置。

並嘗試避免含糊不清的語句,使用字典時使用vals.get('etudiant_ids'),如果找不到鍵而不是錯誤,將返回False。