2222import org .gnucash .android .model .Money ;
2323import org .gnucash .android .model .Account .AccountType ;
2424import org .gnucash .android .model .Transaction ;
25+ import org .gnucash .android .model .Transaction .TransactionType ;
2526
2627import android .content .ContentValues ;
2728import android .content .Context ;
@@ -84,11 +85,8 @@ public long addAccount(Account account){
8485 if ((rowId = getAccountID (account .getUID ())) > 0 ){
8586 //if account already exists, then just update
8687 Log .d (TAG , "Updating existing account" );
87- int rowsAffected = mDb .update (DatabaseHelper .ACCOUNTS_TABLE_NAME , contentValues ,
88+ mDb .update (DatabaseHelper .ACCOUNTS_TABLE_NAME , contentValues ,
8889 DatabaseHelper .KEY_ROW_ID + " = " + rowId , null );
89- if (rowsAffected == 1 ){
90- updateAccount (rowId , DatabaseHelper .KEY_FULL_NAME , getFullyQualifiedAccountName (rowId ));
91- }
9290 } else {
9391 Log .d (TAG , "Adding new account to db" );
9492 rowId = mDb .insert (DatabaseHelper .ACCOUNTS_TABLE_NAME , null , contentValues );
@@ -99,7 +97,20 @@ public long addAccount(Account account){
9997 //update the fully qualified account name
10098 updateAccount (rowId , DatabaseHelper .KEY_FULL_NAME , getFullyQualifiedAccountName (rowId ));
10199 for (Transaction t : account .getTransactions ()) {
102- mTransactionsAdapter .addTransaction (t );
100+ //FIXME: This is a hack until actual splits are implemented
101+ if (t .getDoubleEntryAccountUID ().equals (account .getUID ())){
102+ Transaction trx = new Transaction (t ,false );
103+ // trx.setAmount(trx.getAmount().negate());
104+ if (trx .getType () == TransactionType .DEBIT ) {
105+ trx .setType (TransactionType .CREDIT );
106+ } else {
107+ trx .setType (TransactionType .DEBIT );
108+ }
109+
110+ mTransactionsAdapter .addTransaction (trx );
111+ }
112+ else
113+ mTransactionsAdapter .addTransaction (t );
103114 }
104115 }
105116 return rowId ;
@@ -147,7 +158,7 @@ public boolean destructiveDeleteAccount(long rowId){
147158 //first remove all transactions for the account
148159 Cursor c = mTransactionsAdapter .fetchAllTransactionsForAccount (rowId );
149160 if (c == null )
150- return result ;
161+ return false ;
151162
152163 while (c .moveToNext ()){
153164 long id = c .getLong (DatabaseAdapter .COLUMN_ROW_ID );
@@ -210,7 +221,7 @@ public boolean transactionPreservingDelete(long accountId, long accountReassignI
210221 */
211222 public boolean recursiveDestructiveDelete (long accountId ){
212223 Log .d (TAG , "Delete account with rowId with its transactions and sub-accounts: " + accountId );
213- boolean result = true ;
224+ boolean result = false ;
214225
215226 List <Long > subAccountIds = getSubAccountIds (accountId );
216227 for (long subAccountId : subAccountIds ) {
@@ -425,7 +436,7 @@ public List<Account> getExportableAccounts(){
425436 while (it .hasNext ()){
426437 Account account = it .next ();
427438
428- if (account .hasUnexportedTransactions () == false )
439+ if (! account .hasUnexportedTransactions ())
429440 it .remove ();
430441 }
431442 return accountsList ;
@@ -440,13 +451,12 @@ public List<Account> getExportableAccounts(){
440451 public Cursor fetchAllRecords (){
441452 Log .v (TAG , "Fetching all accounts from db" );
442453 String selection = DatabaseHelper .KEY_TYPE + " != ?" ;
443- Cursor cursor = mDb .query (DatabaseHelper .ACCOUNTS_TABLE_NAME ,
454+ return mDb .query (DatabaseHelper .ACCOUNTS_TABLE_NAME ,
444455 null ,
445456 selection ,
446457 new String []{AccountType .ROOT .name ()},
447458 null , null ,
448459 DatabaseHelper .KEY_NAME + " ASC" );
449- return cursor ;
450460 }
451461
452462 /**
@@ -489,10 +499,9 @@ public boolean deleteRecord(long rowId) {
489499 */
490500 public Cursor fetchAccounts (String condition ){
491501 Log .v (TAG , "Fetching all accounts from db where " + condition );
492- Cursor cursor = mDb .query (DatabaseHelper .ACCOUNTS_TABLE_NAME ,
493- null , condition , null , null , null ,
494- DatabaseHelper .KEY_NAME + " ASC" );
495- return cursor ;
502+ return mDb .query (DatabaseHelper .ACCOUNTS_TABLE_NAME ,
503+ null , condition , null , null , null ,
504+ DatabaseHelper .KEY_NAME + " ASC" );
496505 }
497506
498507 /**
@@ -612,10 +621,9 @@ public Cursor fetchRecentAccounts(int numberOfRecents){
612621 public Cursor fetchFavoriteAccounts (){
613622 Log .v (TAG , "Fetching favorite accounts from db" );
614623 String condition = DatabaseHelper .KEY_FAVORITE + " = 1" ;
615- Cursor cursor = mDb .query (DatabaseHelper .ACCOUNTS_TABLE_NAME ,
624+ return mDb .query (DatabaseHelper .ACCOUNTS_TABLE_NAME ,
616625 null , condition , null , null , null ,
617626 DatabaseHelper .KEY_NAME + " ASC" );
618- return cursor ;
619627 }
620628
621629 /**
0 commit comments