/** * Builds a QIF entry representing this transaction * * @return String QIF representation of this transaction */ public String toQIF() { final String newLine = "\n"; AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(GnuCashApplication.getAppContext()); // all transactions are double transactions String splitAccountFullName = QifHelper.getImbalanceAccountName(mAmount.getCurrency()); if (mDoubleEntryAccountUID != null && mDoubleEntryAccountUID.length() > 0) { splitAccountFullName = accountsDbAdapter.getFullyQualifiedAccountName(mDoubleEntryAccountUID); } StringBuffer transactionQifBuffer = new StringBuffer(); transactionQifBuffer .append(QifHelper.DATE_PREFIX) .append(QifHelper.formatDate(mTimestamp)) .append(newLine); transactionQifBuffer.append(QifHelper.MEMO_PREFIX).append(mName).append(newLine); transactionQifBuffer .append(QifHelper.SPLIT_CATEGORY_PREFIX) .append(splitAccountFullName) .append(newLine); if (mDescription != null && mDescription.length() > 0) { transactionQifBuffer.append(QifHelper.SPLIT_MEMO_PREFIX).append(mDescription).append(newLine); } transactionQifBuffer .append(QifHelper.SPLIT_AMOUNT_PREFIX) .append(mAmount.asString()) .append(newLine); transactionQifBuffer.append(QifHelper.ENTRY_TERMINATOR).append(newLine); accountsDbAdapter.close(); return transactionQifBuffer.toString(); }
@Test public void shouldReassignDescendantAccounts() { loadDefaultAccounts(); String savingsAcctUID = mAccountsDbAdapter.findAccountUidByFullName("Assets:Current Assets:Savings Account"); String currentAssetsUID = mAccountsDbAdapter.findAccountUidByFullName("Assets:Current Assets"); String assetsUID = mAccountsDbAdapter.findAccountUidByFullName("Assets"); assertThat(mAccountsDbAdapter.getParentAccountUID(savingsAcctUID)).isEqualTo(currentAssetsUID); mAccountsDbAdapter.reassignDescendantAccounts(currentAssetsUID, assetsUID); assertThat(mAccountsDbAdapter.getParentAccountUID(savingsAcctUID)).isEqualTo(assetsUID); assertThat(mAccountsDbAdapter.getFullyQualifiedAccountName(savingsAcctUID)) .isEqualTo("Assets:Savings Account"); }