Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
7454 มุมมอง

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
5
ธ.ค. 23
19618
7
มี.ค. 20
8443
1
มี.ค. 17
5897
6
ก.พ. 17
8041
1
ม.ค. 22
2619