Skip to content

Commit 80de032

Browse files
committed
- Fixed: Editing account modifies the transaction type of transfer transactions - fixes #145
- Fixed: Bug causing double entry transactions not to be considered equal - Fixed: Computation of account balance did not properly consider double entries - Improved: Double entry accounting is now activated by default - Improved: Restricted parent/child account hierarchies relationships to those defined by GnuCash accounting (see: http://code.gnucash.org/docs/C/gnucash-help/acct-types.html ) Some code refactoring
1 parent 51fd53e commit 80de032

16 files changed

Lines changed: 233 additions & 97 deletions

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
Change Log
22
===============================================================================
3+
Version 1.3.2 *(2014-03-28)*
4+
----------------------------
5+
* Fixed: Editing account modifies the transaction type of transfer transactions
6+
* Fixed: Bug causing double entry transactions not to be considered equal
7+
* Fixed: Computation of account balance did not properly consider double entries
8+
* Improved: Double-entry accounting is now activated by default
9+
* Improved: Restricted parent/child account hierarchies relationships to those defined by GnuCash accounting
10+
* Improved: Dutch translation
11+
* Improved: German translation
12+
313
Version 1.3.1 *(2014-02-14)*
414
----------------------------
515
* Fixed: Crash when bulk moving 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="26"
20+
android:versionCode="27"
2121
android:versionName="@string/app_version_name" >
2222

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

app/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<description>Gnucash Android companion application</description>
2323

2424
<parent>
25-
<version>1.3.0-SNAPSHOT</version>
25+
<version>1.3.2-SNAPSHOT</version>
2626
<groupId>org.gnucash.android</groupId>
2727
<artifactId>gnucash-android-parent</artifactId>
2828
</parent>

app/res/values-el/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@
405405
<string name="menu_scheduled_transactions">Προγραμματισμένες Κινήσεις</string>
406406
<string name="msg_confirm_create_default_accounts_first_run">GnuCash Android. Καλώς ήρθατε! \nΜπορείτε είτε να δημιουργήσετε
407407
μια ιεραρχία συνηθισμένων λογαριασμών, ή να εισάγετε τη δική σας δομή λογαριασμών GnuCash. \n\nΚαι οι δύο επιλογές είναι επίσης
408-
διαθέσιμες στις Επιλογές της εφαρμογής γι' αυτό μπορείτε να αποφασίσετε αργότερα.
408+
διαθέσιμες στις Επιλογές της εφαρμογής γι\' αυτό μπορείτε να αποφασίσετε αργότερα.
409409
</string>
410410
<string-array name="recurrence_period_strings">
411411
<item>ΚΑΜΙΑ</item>

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.1</string>
20+
<string name="app_version_name">1.3.2</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/res/xml/fragment_account_preferences.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
android:dialogTitle="@string/title_choose_currency"
88
android:title="@string/title_default_currency"
99
android:entries="@array/currency_names"
10-
android:entryValues="@array/currency_codes"/>
10+
android:entryValues="@array/currency_codes"
11+
android:defaultValue="USD"/>
1112
<Preference android:key="@string/key_import_accounts"
1213
android:summary="@string/summary_import_accounts"
1314
android:title="@string/title_import_accounts" />

app/res/xml/fragment_transaction_preferences.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
android:summary="@string/summary_default_transaction_type"/>
2424
<CheckBoxPreference android:summary="@string/summary_use_double_entry"
2525
android:key="@string/key_use_double_entry"
26+
android:defaultValue="true"
2627
android:title="@string/title_use_double_entry"/>
2728
<Preference android:key="@string/key_delete_all_transactions"
2829
android:summary="@string/summary_delete_all_transactions"

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.gnucash.android.model.Money;
2323
import org.gnucash.android.model.Account.AccountType;
2424
import org.gnucash.android.model.Transaction;
25+
import org.gnucash.android.model.Transaction.TransactionType;
2526

2627
import android.content.ContentValues;
2728
import 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
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class Account {
5151
^ anchor for start of string
5252
# the literal #
5353
( start of group
54-
?: indicate a non-capturing group that doesn't generate backreferences
54+
?: indicate a non-capturing group that doesn't generate back-references
5555
[0-9a-fA-F] hexadecimal digit
5656
{3} three times
5757
) end of group
@@ -357,7 +357,7 @@ public int getTransactionCount(){
357357
*/
358358
public boolean hasUnexportedTransactions(){
359359
for (Transaction transaction : mTransactionsList) {
360-
if (transaction.isExported() == false)
360+
if (!transaction.isExported())
361361
return true;
362362
}
363363
return false;

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ public Transaction(Money amount, String name, TransactionType type){
169169
/**
170170
* Copy constructor.
171171
* Creates a new transaction object which is a clone of the parameter.
172-
* <p><b>Note:</b> The unique ID of the transaction is not cloned, but a new one is generated.</p>
172+
* <p><b>Note:</b> The unique ID of the transaction is not cloned if the parameter <code>generateNewUID</code>,
173+
* is set to false. Otherwise, a new one is generated.</p>
173174
* @param transaction Transaction to be cloned
175+
* @param generateNewUID Flag to determine if new UID should be assigned or not
174176
*/
175-
public Transaction(Transaction transaction){
177+
public Transaction(Transaction transaction, boolean generateNewUID){
176178
initDefaults();
177179
setName(transaction.getName());
178180
setDescription(transaction.getDescription());
@@ -182,6 +184,9 @@ public Transaction(Transaction transaction){
182184
setDoubleEntryAccountUID(transaction.getDoubleEntryAccountUID());
183185
setExported(transaction.isExported());
184186
setTime(transaction.getTimeMillis());
187+
if (!generateNewUID){
188+
setUID(transaction.getUID());
189+
}
185190
}
186191

187192
/**

0 commit comments

Comments
 (0)