'Convert lead to opportunity or merge lead and opportunity and open
the freshly created opportunity view.'

@api.multi
def action_apply(self):

    self.ensure_one()
    values = {'team_id': self.team_id.id}
    if self.partner_id:
        values['partner_id'] = self.partner_id.id
    if (self.name == 'merge'):
        leads = self.opportunity_ids.merge_opportunity()
        if (leads.type == 'lead'):
            values.update({'lead_ids': leads.ids, 'user_ids': [self.user_id.id]})
            self.with_context(active_ids=leads.ids)._convert_opportunity(values)
        elif ((not self._context.get('no_force_assignation')) or (not leads.user_id)):
            values['user_id'] = self.user_id.id
            leads.write(values)
    else:
        leads = self.env['crm.lead'].browse(self._context.get('active_ids', []))
        values.update({'lead_ids': leads.ids, 'user_ids': [self.user_id.id]})
        self._convert_opportunity(values)
    return leads[0].redirect_opportunity_view()
