跳至内容
菜单
此问题已终结
4 回复
7366 查看

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

最佳答案

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

Copy error! ;)

编写者 最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
5
12月 23
19542
7
3月 20
8319
1
3月 17
5849
6
2月 17
7939
1
1月 22
2576