我在OpenERP6.0中创建了一个模块,问题是OpenERP6.0不支持与OpenERP7相同的代码,这是函数create:如果有人能帮我解决问题:
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)
问题出现在“if vals['etudiant\u ids'][0][2]:”
if vals['etudiant_ids'][0][2]:
TypeError: 'bool' object has no attribute '__getitem__'
当您访问一个字典时,上面的错误出现了,因为找不到它的键。 更好的调试方法是,使用print语句检查值 打印VAL['etudiant\u ids'], 打印VAL['etudiant\u id'][0], 打印VAL['etudiant\u id'][0][2], 你可以知道钥匙在哪里不取。你知道吗
尽量避免模棱两可的陈述,使用VAL.get公司('etudiant\u ids')使用字典时,如果找不到键,则返回False,而不是error。你知道吗
相关问题 更多 >
编程相关推荐