Skip to content

Commit 4a9cdd4

Browse files
committed
Merge branch 'develop'
2 parents 1902ec2 + 3b99114 commit 4a9cdd4

File tree

8 files changed

+70
-24
lines changed

8 files changed

+70
-24
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Change Log
22
===============================================================================
3+
Version 1.3.3 *(2014-05-26)*
4+
* Reversed changes in the computation of balances, back to pre-v1.3.2 mode (will be re-instated in the future)
5+
36
Version 1.3.2 *(2014-05-23)*
47
----------------------------
58
* Fixed: Editing account modifies the transaction type of transfer transactions

app/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
1919
package="org.gnucash.android"
20-
android:versionCode="28"
20+
android:versionCode="29"
2121
android:versionName="@string/app_version_name" >
2222

2323
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/>

app/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1919
<string name="app_name">GnuCash</string>
20-
<string name="app_version_name">1.3.2</string>
20+
<string name="app_version_name">1.3.3</string>
2121
<string name="title_add_account">Create Account</string>
2222
<string name="title_edit_account">Edit Account</string>
2323
<string name="info_details">Info</string>

app/src/org/gnucash/android/app/GnuCashApplication.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
import android.app.Application;
1919
import android.content.Context;
20+
import android.content.SharedPreferences;
21+
import android.preference.PreferenceManager;
22+
import org.gnucash.android.R;
2023

2124
/**
2225
* An {@link Application} subclass for retrieving static context
@@ -39,4 +42,15 @@ public void onCreate(){
3942
public static Context getAppContext() {
4043
return GnuCashApplication.context;
4144
}
45+
46+
/**
47+
* Returns <code>true</code> if double entry is enabled in the app settings, <code>false</code> otherwise.
48+
* If the value is not set, the default value can be specified in the parameters.
49+
* @param defaultValue Default value to return if double entry is not explicitly set
50+
* @return <code>true</code> if double entry is enabled, <code>false</code> otherwise
51+
*/
52+
public static boolean isDoubleEntryEnabled(boolean defaultValue){
53+
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
54+
return sharedPrefs.getBoolean(context.getString(R.string.key_use_double_entry), defaultValue);
55+
}
4256
}

app/src/org/gnucash/android/db/AccountsDbAdapter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,13 @@ public Money getAccountBalance(long accountId){
546546
balance = balance.add(subBalance);
547547
}
548548
}
549-
return balance.add(getAccount(accountId).getBalance());
549+
550+
return balance.add(mTransactionsAdapter.getTransactionsSum(accountId));
551+
552+
// properly compute the account balance taking double entry into account
553+
// TODO: re-enable this when splits are added
554+
// return balance.add(getAccount(accountId).getBalance());
555+
550556
}
551557

552558
/**

app/src/org/gnucash/android/db/TransactionsDbAdapter.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.database.Cursor;
2222
import android.database.sqlite.SQLiteStatement;
2323
import android.util.Log;
24+
import org.gnucash.android.app.GnuCashApplication;
2425
import org.gnucash.android.model.Account;
2526
import org.gnucash.android.model.Money;
2627
import org.gnucash.android.model.Transaction;
@@ -186,14 +187,25 @@ public List<Transaction> getAllTransactionsForAccount(String accountUID){
186187
while (c.moveToNext()) {
187188
Transaction transaction = buildTransactionInstance(c);
188189
String doubleEntryAccountUID = transaction.getDoubleEntryAccountUID();
189-
// Negate double entry transactions for the transfer account
190+
191+
//one transaction in this case represents both sides of the split
190192
if (doubleEntryAccountUID != null && doubleEntryAccountUID.equals(accountUID)){
191-
if (transaction.getType() == TransactionType.DEBIT) {
192-
transaction.setType(TransactionType.CREDIT);
193-
} else {
194-
transaction.setType(TransactionType.DEBIT);
195-
}
193+
transaction.setAmount(transaction.getAmount().negate());
194+
/*
195+
//use this to properly compute the account balance
196+
if (GnuCashApplication.isDoubleEntryEnabled(false)) {
197+
if (transaction.getType() == TransactionType.DEBIT) {
198+
transaction.setType(TransactionType.CREDIT);
199+
} else {
200+
transaction.setType(TransactionType.DEBIT);
201+
}
202+
} else {
203+
// Negate double entry transactions for the transfer account
204+
transaction.setAmount(transaction.getAmount().negate());
205+
}
206+
*/
196207
}
208+
197209
transactionsList.add(transaction);
198210
}
199211
c.close();

app/src/org/gnucash/android/model/Account.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -371,21 +371,30 @@ public boolean hasUnexportedTransactions(){
371371
public Money getBalance(){
372372
Money balance = new Money(new BigDecimal(0), this.mCurrency);
373373
for (Transaction transaction : mTransactionsList) {
374-
boolean isDebitAccount = getAccountType().hasDebitNormalBalance();
375-
boolean isDebitTransaction = transaction.getType() == TransactionType.DEBIT;
376-
if (isDebitAccount) {
377-
if (isDebitTransaction) {
378-
balance = balance.add(transaction.getAmount());
379-
} else {
380-
balance = balance.subtract(transaction.getAmount());
381-
}
382-
} else {
383-
if (isDebitTransaction) {
384-
balance = balance.subtract(transaction.getAmount());
385-
} else {
386-
balance = balance.add(transaction.getAmount());
387-
}
388-
}
374+
balance = balance.add(transaction.getAmount());
375+
376+
/*
377+
//TODO: Re-enable proper computation of balance for double-entries in the future
378+
if (GnuCashApplication.isDoubleEntryEnabled(false)) {
379+
boolean isDebitAccount = getAccountType().hasDebitNormalBalance();
380+
boolean isDebitTransaction = transaction.getType() == TransactionType.DEBIT;
381+
if (isDebitAccount) {
382+
if (isDebitTransaction) {
383+
balance = balance.add(transaction.getAmount());
384+
} else {
385+
balance = balance.subtract(transaction.getAmount());
386+
}
387+
} else {
388+
if (isDebitTransaction) {
389+
balance = balance.subtract(transaction.getAmount());
390+
} else {
391+
balance = balance.add(transaction.getAmount());
392+
}
393+
}
394+
} else { //not using double entry
395+
balance = balance.add(transaction.getAmount());
396+
}
397+
*/
389398
}
390399
return balance;
391400
}

app/src/org/gnucash/android/ui/account/AccountsActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ private void init() {
279279
boolean firstRun = prefs.getBoolean(getString(R.string.key_first_run), true);
280280
if (firstRun){
281281
createDefaultAccounts();
282+
//default to using double entry and save the preference explicitly
283+
prefs.edit().putBoolean(getString(R.string.key_use_double_entry), true).commit();
282284
}
283285

284286
if (hasNewFeatures()){

0 commit comments

Comments
 (0)