Odoo Help


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.


Copying Many2many field values to another Many2many field

on 5/22/16, 1:26 PM 281 views

Hello, can someone help me with this please.

I have a situation, where, when I create an object, I would like to copy values of a Many2many field (subject_ids) from course object (which has a many2one relation with the batch object) to a Many2many field(subject_ids) in batch object. 

following is the code sample:

class Subject(models.Model):

    course_ids = fields.Many2many('course', string='Course(s)')

    batch_ids = fields.Many2many('batch', string='Batch(s)')

class Course(models.Model):

     subject_ids = fields.Many2many('subject', string='Subject(s)')

class Batch(models.Model):

  course_ids = fields.Many2many('course', string='Course(s)')  

   subject_ids = fields.Many2many('subject', string='Subject(s)')  



I tried this in the batch object but throws an error: list index out of range @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]

on 5/22/16, 3:38 PM

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)


Asked: 5/22/16, 1:26 PM
Seen: 281 times
Last updated: 5/22/16, 3:22 PM