code: def replace_account_types(env, type_spec, unlink=True):
      
      logger = logging.getLogger('OpenUpgrade')
      for old_type, new_type in type_spec:
          try:
              type8 = env.ref(old_type)
          except ValueError:
              if getattr(threading.currentThread(), 'testing', False):
                  raise
              continue
  
          type9 = env.ref(new_type)
          for table in ('account_account',
                        'account_account_template',
                        'account_move_line'):
              env.cr.execute(
                  "UPDATE %s SET user_type_id = %s WHERE user_type_id = %s",
                  (AsIs(table), type9.id, type8.id))
          if unlink:
              with env.cr.savepoint():
                  try:
                      type8.unlink()
                  except Exception as e:
                      logger.info(
                          'Could not remove account type %s: %s',
                          old_type, e)
docs: Replace old account types with their replacements. The old account
      type is allowed not to exist anymore, except when running unit tests.
      :param type_spec: list of tuples (xmlid of old account.account.type, \
  xmlid of new account.account.type)
      :param unlink: attempt to unlink the old account type