Odoo Help

Welcome!

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.

0

Several levels of One2many

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

Hi!

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.


    @api.onchange('shift_template_id')
def _onchange_template_id(self):
if self.shift_template_id:
vals = []
for ticket in self.shift_ticket_ids:
ticket.unlink()
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?

Thanks.

Julien

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)

Stats

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