类型错误:'int'对象不是可迭代的 odoo8



在 Odoo 8 上,我尝试执行此操作:

@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]

我收到此错误: 类型错误:"int"对象不可迭代

一些想法 ?

您的查询只返回一个值,因此请使用self.env.cr.fetchone((试试这个来了解你值的类型:

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

如果不是listtuple,则不能执行self.env.cr.fetchone(([0]

注意:你没有显示女巫线导致错误,所以我认为这是 费希切内[0]

最新更新