<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def switch_company(ctx, company):
 """Context manager to switch current company. Accepts both company record and xmlid. """

    current_company = ctx.env.user.company_id
    ctx.env.user.company_id = safe_record(ctx, company)
    yield ctx
    ctx.env.user.company_id = current_company