This is a tricky question.
I am trying to add some fields to a many2many table. I was googling and I found that I have to create an intermediate table to stores those fields. But it is not working very well.
My example: I created a table (training_course). A partner can join to many training_course, and a training_course is made up by many partners (So, this is a many2many relationship). I have to store the date when the partner joined the course.
So, in the partner form, I have to see the list of the courses he has joined, everyone with their dates.
My code is:
res_partner_course_rel (This is the intermediate class generated by me -with name = 'res.partner.course.rel'-)
_columns = {
'partner_id': fields.many2one('res.partner', 'Partner', ondelete='cascade'),
'course_id': fields.many2one('training.course', 'Course', ondelete='cascade'),
'date': fields.date('Joining date'),
}
res_partner
_columns = {
'courses': fields.many2many('res.partner.course.rel', id1='partner_id', id2='partner_course_rel_id', string='Courses'),
}
The problems I have are:
- In the partners form, when I click on add a new record in the resultant list, I had to select the partner (which is a nosense, because it must be the current one).
- The resultant list only shows a column (partner), when I would like to show two (course and date).
Anyone can help me a bit, please? I am trying several things but I cannot manage what I need.