简体   繁体   中英

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:

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]:"

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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