public static boolean updateAccountDetails(Context context, OEUser userObject) {

    boolean flag = false;
    OEUser user = OpenERPAccountManager.getAccountDetail(context, userObject.getAndroidName());
    Bundle userBundle = userObject.getAsBundle();
    if (user != null) {
      AccountManager accMgr = AccountManager.get(context);
      for (String key : userBundle.keySet()) {
        accMgr.setUserData(
            OpenERPAccountManager.getAccount(context, user.getAndroidName()),
            key,
            userBundle.getString(key));
      }

      flag = true;
    }
    return flag;
  }
  /**
   * Login user.
   *
   * @param context the context
   * @param username the username
   * @return the user object
   */
  public static OEUser loginUser(Context context, String username) {
    OEUser userData = null;

    List<OEUser> allAccounts = OpenERPAccountManager.fetchAllAccounts(context);
    for (OEUser user : allAccounts) {
      OpenERPAccountManager.logoutUser(context, user.getAndroidName());
    }

    userData = OpenERPAccountManager.getAccountDetail(context, username);
    if (userData != null) {
      AccountManager accMgr = AccountManager.get(context);

      accMgr.setUserData(
          OpenERPAccountManager.getAccount(context, userData.getAndroidName()), "isactive", "true");
    }
    current_user = userData;
    return userData;
  }
 /**
  * Creates the account.
  *
  * @param context the context
  * @param bundleData the bundle data
  * @return true, if successful
  */
 public static boolean createAccount(Context context, OEUser bundleData) {
   AccountManager accMgr = null;
   accMgr = AccountManager.get(context);
   String accountType = PARAM_AUTHTOKEN_TYPE;
   String password = String.valueOf(bundleData.getPassword());
   String accountName = bundleData.getAndroidName();
   Account account = new Account(accountName, accountType);
   Bundle bundle = bundleData.getAsBundle();
   return accMgr.addAccountExplicitly(account, password, bundle);
 }
  /**
   * Gets the account detail.
   *
   * @param context the context
   * @param username the username
   * @return the account detail
   */
  public static OEUser getAccountDetail(Context context, String username) {

    List<OEUser> allAccounts = OpenERPAccountManager.fetchAllAccounts(context);
    for (OEUser user : allAccounts) {
      if (user.getAndroidName().equals(username)) {
        return user;
      }
    }
    return null;
  }
  /**
   * Logout user.
   *
   * @param context the context
   * @param username the username
   * @return true, if successful
   */
  public static boolean logoutUser(Context context, String username) {
    boolean flag = false;
    OEUser user = OpenERPAccountManager.getAccountDetail(context, username);
    Account account = OpenERPAccountManager.getAccount(context, user.getAndroidName());
    if (user != null) {
      if (cancelAllSync(account)) {
        AccountManager accMgr = AccountManager.get(context);
        user.setIsactive(false);

        accMgr.setUserData(account, "isactive", "0");
        flag = true;
        current_user = null;
      }
    }
    return flag;
  }
  /**
   * Gets the account.
   *
   * @param context the context
   * @param username the username
   * @return the account
   */
  public static Account getAccount(Context context, String username) {
    AccountManager accMgr = AccountManager.get(context);
    Account[] accounts = accMgr.getAccountsByType(PARAM_AUTHTOKEN_TYPE);

    Account userAc = null;
    for (Account account : accounts) {

      OEUser userData = new OEUser();
      userData.fillFromAccount(accMgr, account);

      if (userData != null) {
        if (userData.getAndroidName().equals(username)) {
          userAc = account;
        }
      }
    }
    return userAc;
  }