简体   繁体   English

创建函数 openerp 6.0

[英]create function openerp 6.0

I created a module in openerp 6.0, the problem that openerp 6.0 did not support the same code as openerp 7, this is the function create: if some one can help me to solve the problem:我在openerp 6.0中创建了一个模块,openerp 6.0不支持与openerp 7相同的代码的问题,这是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)

the problem is in "if vals['etudiant_ids'][0][2]:"问题在于“如果 vals['etudiant_ids'][0][2]:”

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

The above error comes, when you are accessing a dictionary, whose key is not found.当您访问未找到其键的字典时,会出现上述错误。 The better way to debug is, use print statements to check the value print vals['etudiant_ids'], print vals['etudiant_ids'][0], print vals['etudiant_ids'][0][2], and you can know where the key is not fetching.更好的调试方法是,使用print语句检查值print vals['etudiant_ids']、print vals['etudiant_ids'][0]、print vals['etudiant_ids'][0][2],就可以了知道密钥未获取的位置。

and try to avoid ambigous statements, use vals.get('etudiant_ids') when using dictionaries, which will return False if the key not found instead of error.并尽量避免含糊不清的语句,在使用字典时使用 vals.get('etudiant_ids'),如果未找到键而不是错误,它将返回 False。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM