Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

List index out of range error

By
Eric
on 12/30/13, 7:13 PM 3,718 views

Hello, I am trying to write data to a field in the mail.message table, but keep getting an "IndexError: list index out of range" error whenever i run the code. The field I am trying to write to is the model field, and I believe its a related field. here is a sample of the code

    mail_msg = self.pool.get('mail.message')

    # msg_ids is the id of the message 
    msg_ids = context.get('msg_id')

    # gets the message data with the id of the selected message
    message = mail_msg.browse(cr, uid, msg_ids , context)

    # finds the related partner ids and returns as a list of objects
    related_ids = mail_msg.browse(cr,uid,msg_ids ,context=None)

    # will store only the ids of the partners from the related_ids list
    related_id_list = []
    for _id in related_ids.partner_ids:
        related_id_list.append(_id.id)


    values = {
        'body': message.body,
        'date': message.date,
        'model': message.model,    # error caused here !!
        'record_name': message.record_name,
        'subject': message.subject,
        'parent_id': message.parent_id.id,
        'res_id': related_id_list[2],   # Update this field with another partner id
        'author_id': message.author_id.id,
    }

    new_msg_created = mail_msg.create(cr, uid, values, context = None)

It seems like I need to relate the value somehow like in the parent_id and author_id lines, but I'm not sure how to do it for the model. Here is a traceback message that I was getting:

Server Traceback (most recent call last): File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server\openerp\addons\web\session.py", line 89, in send File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\netsvc.py", line 292, in dispatch_rpc File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\service\web_services.py", line 626, in dispatch File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\osv\osv.py", line 188, in execute_kw File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\osv\osv.py", line 131, in wrapper File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\osv\osv.py", line 197, in execute File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\osv\osv.py", line 185, in execute_cr File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server\openerp\addons\mail_attach_history\mail_attach_history.py", line 53, in attach_history File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\osv\orm.py", line 4270, in write File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\osv\orm.py", line 4627, in _store_set_values File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\osv\fields.py", line 1133, in get File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server\openerp\addons\mail\mail_message.py", line 81, in _get_record_name IndexError: list index out of range

0
Eric
On 12/30/13, 9:01 PM

I was able to get around this error by using an sql update statement with the database cursor. I didnt want to go around the ORM to do it, but this way does work. Here is a sample of what I did:

update = "update \"table_name\" set \"field_name\" = '%s' where \"other_field_name\" = '%s'" % ('value1', 'value2') cr.execute(str(update))

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 12/30/13, 7:13 PM
Seen: 3718 times
Last updated: 3/16/15, 8:10 AM