Odoo Help


Several levels of One2many

Julien Weste
on 4/19/16, 2:09 PM 596 views


I've got these 3 classes: shift.shift, shift.ticket and shift.registration.

Dans shift.shift, j'ai:

shift_ticket_ids = fields.One2many(
'shift.ticket', 'shift_id', string='Shift Ticket',
default=lambda rec: rec._default_shift_tickets())

et dans shift.ticket, j'ai:

    registration_ids = fields.One2many(
'shift.registration', 'shift_ticket_id', 'Registrations')

In an onchange method on the shift.shift class, I'd like to create some shift ticket and shift.registration records.

def _onchange_template_id(self):
if self.shift_template_id:
vals = []
for ticket in self.shift_ticket_ids:
for ticket in self.shift_template_id.shift_ticket_ids:
attendee_vals = []
for attendee in ticket.registration_ids:
attendee_vals.append((0, 0, {
'partner_id': attendee.partner_id.id,
'state': 'draft',
'email': attendee.email,
'phone': attendee.phone,
'name': attendee.name,
ticket_vals = {
'name': ticket.name,
'product_id': ticket.product_id.id,
'price': ticket.price,
'deadline': ticket.deadline,
'seats_availability': ticket.seats_availability,
'registration_ids': attendee_vals,
vals.append((0, 0, ticket_vals))
self.shift_ticket_ids = vals

But this doesn't work: the shift_ticket records are created, but not the shift_registration records.

How could I manage this situation?



About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 4/19/16, 2:09 PM
Seen: 596 times
Last updated: 4/19/16, 3:45 PM