'Create or update registrations linked to a sale order line. A sale
order line has a product_uom_qty attribute that will be the number of
registrations linked to this line. This method update existing registrations
and create new one for missing one.'

@api.multi
def _update_registrations(self, confirm=True, registration_data=None):

    Registration = self.env['event.registration']
    registrations = Registration.search([('sale_order_line_id', 'in', self.ids)])
    for so_line in self.filtered('event_id'):
        existing_registrations = registrations.filtered((lambda self: (self.sale_order_line_id.id == so_line.id)))
        if confirm:
            existing_registrations.filtered((lambda self: (self.state != 'open'))).confirm_registration()
        else:
            existing_registrations.filtered((lambda self: (self.state == 'cancel'))).do_draft()
        for count in range((int(so_line.product_uom_qty) - len(existing_registrations))):
            registration = {}
            if registration_data:
                registration = registration_data.pop()
            registration['sale_order_line_id'] = so_line
            Registration.with_context(registration_force_draft=True).create(Registration._prepare_attendee_values(registration))
    return True
