'This function returns an action that display existing delivery orders
of given sales order ids. It can either be a in a list or in a form
view, if there is only one delivery order to show.'

@api.multi
def action_view_delivery(self):

    action = self.env.ref('stock.action_picking_tree_all').read()[0]
    pickings = self.mapped('picking_ids')
    if (len(pickings) > 1):
        action['domain'] = [('id', 'in', pickings.ids)]
    elif pickings:
        action['views'] = [(self.env.ref('stock.view_picking_form').id, 'form')]
        action['res_id'] = pickings.id
    return action
