类型错误:“诠释”对象不是可迭代odoo8
问题描述:
上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]
我得到这个错误: 类型错误:“诠释”对象不是可迭代
一些想法?
答
您的查询返回只有一个值,因此使用self.env.cr.fetchone() 试试这个知道类型的你的价值:
print type(self.env.cr.fetchone())
,如果它不是list
或tuple
比你不能做self.env.cr.fetchone()[0]
NB: you didn't show witch line cause the error so i'm thinking it's fechtcheone[0]