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

By
Narender
on 5/23/16, 6:28 AM 323 views

Hi, I am trying to copy ids into a many2many field, but it throws list index out of range error. Can someone please help me where I am doing a mistake


@api.onchange('course_id')
def get_default_subject_ids(self):
    res = []
    if len(self.course_id.subject_ids):
        for subject in self.course_id.subject_ids :
            res.append(subject.id)
        self.subject_ids= [0,0,res]
    return True
 
Debugged it and observed that it throws list index out of range @ self.subject_ids= [0,0,res]

Regards,

Narender

i have tried that before, but it then throws

argument of type 'bool' is not iterable error

Narender
on 5/23/16, 7:42 AM
1

Jusab Sida (jsi)

--Jusab Sida (jsi)--
Tiny ERP Pvt Ltd
http://www.odoo.com
874
| 2 1 5
Gandhinagar, India
--Jusab Sida (jsi)--


Jusab Sida (jsi)
On 5/23/16, 7:31 AM

EDITED:

can you try this one?: self.subject_ids = [(6, 0, res)]

almost, check https://www.odoo.com/documentation/9.0/reference/orm.html#openerp.models.Model.write the command you want is probably 6, not 0

Martin Trigaux (mat)
on 5/23/16, 7:49 AM

Copy error! ;)

Jusab Sida (jsi)
on 5/23/16, 7:56 AM
0
Narender
On 5/23/16, 7:50 AM

for [(0,0,res)] it throws 'list' object has no attribute 'iteritems' error

and for 

[(6,0,res)] it throws argument of type 'bool' is not iterable error

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

1 follower(s)

Stats

Asked: 5/23/16, 6:28 AM
Seen: 323 times
Last updated: 5/23/16, 7:50 AM