2017-03-17 138 views
-2

上odoo 8我嘗試執行此操作:類型錯誤:「詮釋」對象不是可迭代odoo8

@api.onchange('projetbc_ligne_ids') 
def onchange_evalID(self): 
    self.test= self.projetbc_ligne_ids.produit.id 
    query = "SELECT sum(quantite) FROM projet_bc_ligne where produit = %s" 
    self.env.cr.execute(query, (tuple(self.projetbc_ligne_ids.produit.id),)) 
    # self.env.cr.execute("SELECT sum(quantite) FROM projet_bc_ligne where produit = %s",(tuple(self.projetbc_ligne_ids.produit.id),)) 
    self.projetbc_ids.quantite_encoure = self.env.cr.fetchone()[0] 

我得到這個錯誤: 類型錯誤:「詮釋」對象不是可迭代

一些想法?

回答

0

您的查詢返回只有一個值,因此使用self.env.cr.fetchone() 試試這個知道類型的你的價值:

print type(self.env.cr.fetchone()) 

,如果它不是listtuple比你不能做self.env.cr.fetchone()[0]

NB: you didn't show witch line cause the error so i'm thinking it's fechtcheone[0]

相關問題