Skip to content

Commit

Permalink
Merge branch 'hotfix/account_balance'
Browse files Browse the repository at this point in the history
  • Loading branch information
codinguser committed Nov 5, 2015
2 parents c2bbc97 + c593851 commit bbe3e2d
Show file tree
Hide file tree
Showing 85 changed files with 1,741 additions and 658 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
Change Log
===============================================================================
Version 2.0.1 *(2015-11-05)*
----------------------------
* Feature: Menu options for moving/duplicating transactions
* Fixed: Invalid QIF exported, causing crashes when importing on desktop
* Fixed: Account delete dialog not displaying properly / only partially deleting transactions
* Fixed: Moving transaction to another account from within the split editor sets the amount to zero
* Improved: Amounts now use standard commodities & fraction digit on all devices

Version 2.0.0 *(2015-11-01)*
----------------------------
* Feature: Updated app design to use Material Design guidelines
Expand Down
26 changes: 22 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ apply plugin: 'io.fabric'

def versionMajor = 2
def versionMinor = 0
def versionPatch = 0
def versionBuild = 8
def versionPatch = 1
def versionBuild = 3

def buildTime() {
def df = new SimpleDateFormat("yyyyMMdd HH:mm 'UTC'")
Expand Down Expand Up @@ -127,9 +127,26 @@ android {
}
}

/**
* Create the Crashlytics properties file when building on CI
* @return
*/
def initCrashlyticsPropertiesIfNeeded() {
def propertiesFile = file('fabric.properties')
if (!propertiesFile.exists()) {
def commentMessage = "This is autogenerated crashlytics property from system environment to prevent key to be committed to source control."
ant.propertyfile(file: "fabric.properties", comment: commentMessage) { //the keys added here are invalid, just placeholders to make builds pass
entry(key: "apiSecret", value: "bd4e83a9a4c35fbf1fbe8d9ccce9443eebb9d5835605f9d06767850e0f1e5b22")
entry(key: "apiKey", value: "46fe045d00d4ad8a71014c53567be3368e10bd64")
}
}
}

def adb = android.getAdbExe().toString()

afterEvaluate {
initCrashlyticsPropertiesIfNeeded()

task grantAnimationPermissionDevel(type: Exec, dependsOn: 'installDevelopmentDebug') { // or install{productFlavour}{buildType}
commandLine "$adb", 'devices'
standardOutput = new ByteArrayOutputStream()
Expand All @@ -138,11 +155,13 @@ afterEvaluate {
output.eachLine {
def serial = it.split("\\s")[0]
commandLine "$adb -s $serial shell pm grant $android.productFlavors.development.applicationId android.permission.SET_ANIMATION_SCALE".split(' ')
commandLine "$adb -s $serial shell pm grant $android.productFlavors.development.applicationId android.permission.WRITE_EXTERNAL_STORAGE".split(' ')
}
}

task grantAnimationPermissionProduction(type: Exec, dependsOn: 'installProductionDebug'){
commandLine "$adb -e shell pm grant $android.defaultConfig.applicationId android.permission.SET_ANIMATION_SCALE".split(' ')
commandLine "$adb -e shell pm grant $android.defaultConfig.applicationId android.permission.WRITE_EXTERNAL_STORAGE".split(' ')
}
// When launching individual tests from Android Studio, it seems that only the assemble tasks
// get called directly, not the install* versions
Expand Down Expand Up @@ -173,7 +192,6 @@ dependencies {
'org.jraf:android-switch-backport:2.0.1@aar',
'com.github.PhilJay:MPAndroidChart:v2.1.3',
'joda-time:joda-time:2.7',
'org.ocpsoft.prettytime:prettytime:3.2.7.Final',
'com.google.android.gms:play-services-drive:7.0.0',
'com.jakewharton:butterknife:7.0.1',
'com.kobakei:ratethisapp:0.0.3',
Expand All @@ -188,7 +206,7 @@ dependencies {
exclude module: 'httpclient'
}

compile('com.crashlytics.sdk.android:crashlytics:2.5.0@aar') {
compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
transitive = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.gnucash.android.db.TransactionsDbAdapter;
import org.gnucash.android.model.Account;
import org.gnucash.android.model.AccountType;
import org.gnucash.android.model.Commodity;
import org.gnucash.android.model.Money;
import org.gnucash.android.model.Split;
import org.gnucash.android.model.Transaction;
Expand Down Expand Up @@ -80,7 +81,7 @@
@RunWith(AndroidJUnit4.class)
public class AccountsActivityTest extends ActivityInstrumentationTestCase2<AccountsActivity> {
private static final String DUMMY_ACCOUNT_CURRENCY_CODE = "USD";
private static final Currency DUMMY_ACCOUNT_CURRENCY = Currency.getInstance(DUMMY_ACCOUNT_CURRENCY_CODE);
private static final Commodity DUMMY_ACCOUNT_CURRENCY = Commodity.getInstance(DUMMY_ACCOUNT_CURRENCY_CODE);
private static final String DUMMY_ACCOUNT_NAME = "Dummy account";
public static final String DUMMY_ACCOUNT_UID = "dummy-account";
private DatabaseHelper mDbHelper;
Expand Down Expand Up @@ -115,7 +116,7 @@ public void setUp() throws Exception {

Account account = new Account(DUMMY_ACCOUNT_NAME);
account.setUID(DUMMY_ACCOUNT_UID);
account.setCurrency(Currency.getInstance(DUMMY_ACCOUNT_CURRENCY_CODE));
account.setCommodity(Commodity.getInstance(DUMMY_ACCOUNT_CURRENCY_CODE));
mAccountsDbAdapter.addRecord(account);
refreshAccountsList();
}
Expand Down Expand Up @@ -201,7 +202,7 @@ public void testCreateAccount(){
@Test
public void testChangeParentAccount() {
final String accountName = "Euro Account";
Account account = new Account(accountName, Currency.getInstance("EUR"));
Account account = new Account(accountName, Commodity.EUR);
mAccountsDbAdapter.addRecord(account);

refreshAccountsList();
Expand Down Expand Up @@ -282,7 +283,7 @@ public void editingAccountShouldNotDeleteTransactions(){
.perform(click());

Account account = new Account("Transfer Account");
account.setCurrency(DUMMY_ACCOUNT_CURRENCY);
account.setCommodity(Commodity.getInstance(DUMMY_ACCOUNT_CURRENCY.getCurrencyCode()));
Transaction transaction = new Transaction("Simple trxn");
transaction.setCurrencyCode(DUMMY_ACCOUNT_CURRENCY.getCurrencyCode());
Split split = new Split(new Money(BigDecimal.TEN, DUMMY_ACCOUNT_CURRENCY), account.getUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.gnucash.android.test.ui;

import android.Manifest;
import android.app.AlertDialog;
import android.content.pm.PackageManager;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
Expand Down Expand Up @@ -48,8 +49,10 @@
import org.gnucash.android.ui.account.AccountsActivity;
import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;

import java.io.File;
import java.util.Currency;
Expand All @@ -68,6 +71,7 @@
import static org.hamcrest.Matchers.allOf;

@RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ExportTransactionsTest extends
ActivityInstrumentationTestCase2<AccountsActivity> {

Expand Down Expand Up @@ -136,7 +140,7 @@ public void testOfxExport(){
}

@Test
public void shouldNotOfferXmlExportInSingleEntryMode(){
public void whenInSingleEntry_shouldHideXmlExportOption(){
PreferenceManager.getDefaultSharedPreferences(mAcccountsActivity)
.edit().putBoolean(mAcccountsActivity.getString(R.string.key_use_double_entry), false)
.commit();
Expand Down Expand Up @@ -174,7 +178,7 @@ public void testExport(ExportFormat format){
mAcccountsActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE}, 0x23);

onView(withId(android.R.id.button1)).perform(click());
onView(withId(AlertDialog.BUTTON_POSITIVE)).perform(click());
}
}

Expand Down Expand Up @@ -216,7 +220,7 @@ public void testDeleteTransactionsAfterExport(){
* Does not work on Travis yet
*/
@Test
public void shouldCreateExportSchedule(){
public void testShouldCreateExportSchedule(){
DrawerActions.openDrawer(R.id.drawer_layout);
onView(withText(R.string.nav_menu_export)).perform(click());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.gnucash.android.importer.GncXmlImporter;
import org.gnucash.android.model.Account;
import org.gnucash.android.model.AccountType;
import org.gnucash.android.model.Commodity;
import org.gnucash.android.model.Money;
import org.gnucash.android.model.Split;
import org.gnucash.android.model.Transaction;
Expand Down Expand Up @@ -94,7 +95,7 @@ public class PieChartReportTest extends ActivityInstrumentationTestCase2<Reports
private static final String GIFTS_RECEIVED_INCOME_ACCOUNT_UID = "b01950c0df0890b6543209d51c8e0b0f";
private static final String GIFTS_RECEIVED_INCOME_ACCOUNT_NAME = "Gifts Received";

public static final Currency CURRENCY = Currency.getInstance("USD");
public static final Commodity CURRENCY = Commodity.getInstance("USD");

private AccountsDbAdapter mAccountsDbAdapter;
private TransactionsDbAdapter mTransactionsDbAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.gnucash.android.db.SplitsDbAdapter;
import org.gnucash.android.db.TransactionsDbAdapter;
import org.gnucash.android.model.Account;
import org.gnucash.android.model.Commodity;
import org.gnucash.android.model.Money;
import org.gnucash.android.model.Split;
import org.gnucash.android.model.Transaction;
Expand All @@ -56,6 +57,7 @@
import java.util.List;
import java.util.Locale;

import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.clearText;
import static android.support.test.espresso.action.ViewActions.click;
Expand All @@ -69,6 +71,7 @@
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

Expand Down Expand Up @@ -121,11 +124,11 @@ public void setUp() throws Exception {
mTransactionTimeMillis = System.currentTimeMillis();
Account account = new Account(DUMMY_ACCOUNT_NAME);
account.setUID(DUMMY_ACCOUNT_UID);
account.setCurrency(Currency.getInstance(CURRENCY_CODE));
account.setCommodity(Commodity.getInstance(CURRENCY_CODE));

Account account2 = new Account(TRANSFER_ACCOUNT_NAME);
account2.setUID(TRANSFER_ACCOUNT_UID);
account2.setCurrency(Currency.getInstance(CURRENCY_CODE));
account2.setCommodity(Commodity.getInstance(CURRENCY_CODE));

mAccountsDbAdapter.addRecord(account);
mAccountsDbAdapter.addRecord(account2);
Expand Down Expand Up @@ -475,6 +478,79 @@ public void testDeleteTransaction(){
assertEquals(0, mTransactionsDbAdapter.getTransactionsCount(id));
}

@Test
public void testMoveTransaction(){
Account account = new Account("Move account");
account.setCommodity(Commodity.getInstance(CURRENCY_CODE));
mAccountsDbAdapter.addRecord(account);

assertThat(mTransactionsDbAdapter.getAllTransactionsForAccount(account.getUID())).hasSize(0);

onView(withId(R.id.options_menu)).perform(click());
onView(withText(R.string.menu_move_transaction)).perform(click());

onView(withId(R.id.btn_save)).perform(click());

assertThat(mTransactionsDbAdapter.getAllTransactionsForAccount(DUMMY_ACCOUNT_UID)).hasSize(0);

assertThat(mTransactionsDbAdapter.getAllTransactionsForAccount(account.getUID())).hasSize(1);

}

// @Test //// FIXME: 03.11.2015 fix and re-enable this test
public void editingSplit_shouldNotSetAmountToZero(){
setDoubleEntryEnabled(true);
mTransactionsDbAdapter.deleteAllRecords();

Account account = new Account("Z Account", Commodity.getInstance(CURRENCY_CODE));
mAccountsDbAdapter.addRecord(account);

onView(withId(R.id.fab_create_transaction)).perform(click());

onView(withId(R.id.input_transaction_name)).perform(typeText("Test Split"));
onView(withId(R.id.input_transaction_amount)).perform(typeText("1024"));

onView(withId(R.id.menu_save)).perform(click());

onView(withText("Test Split")).perform(click());
onView(withId(R.id.fab_edit_transaction)).perform(click());

onView(withId(R.id.btn_split_editor)).perform(click());

// onView(withSpinnerText(DUMMY_ACCOUNT_NAME)).perform(click()); //// FIXME: 03.11.2015 properly select the spinner
onData(withId(R.id.input_accounts_spinner))
.inAdapterView(withId(R.id.split_list_layout))
.atPosition(1)
.perform(click());
onData(allOf(is(instanceOf(String.class)), is(account.getFullName()))).perform(click());
// onView(withText(account.getFullName())).perform(click());

onView(withId(R.id.menu_save)).perform(click());
onView(withId(R.id.menu_save)).perform(click());

//split should have moved from account, it should now be empty
onView(withId(R.id.empty_view)).check(matches(isDisplayed()));

assertThat(mAccountsDbAdapter.getAccountBalance(DUMMY_ACCOUNT_UID)).isEqualTo(Money.createZeroInstance(CURRENCY_CODE));

//split
assertThat(mAccountsDbAdapter.getAccountBalance(account.getUID())).isEqualTo(new Money("1024", CURRENCY_CODE));
}

@Test
public void testDuplicateTransaction(){
assertThat(mTransactionsDbAdapter.getAllTransactionsForAccount(DUMMY_ACCOUNT_UID)).hasSize(1);

onView(withId(R.id.options_menu)).perform(click());
onView(withText(R.string.menu_duplicate_transaction)).perform(click());

List<Transaction> dummyAccountTrns = mTransactionsDbAdapter.getAllTransactionsForAccount(DUMMY_ACCOUNT_UID);
assertThat(dummyAccountTrns).hasSize(2);

assertThat(dummyAccountTrns.get(0).getDescription()).isEqualTo(dummyAccountTrns.get(1).getDescription());
assertThat(dummyAccountTrns.get(0).getTimeMillis()).isNotEqualTo(dummyAccountTrns.get(1).getTimeMillis());
}

//TODO: add normal transaction recording
@Test
public void testLegacyIntentTransactionRecording(){
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<meta-data android:name="io.fabric.ApiKey" android:value="46fe045d00d4ad8a71014c53567be3368e10bd64"/>
</application>

</manifest>
12 changes: 12 additions & 0 deletions app/src/main/java/org/gnucash/android/app/GnuCashApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.gnucash.android.db.ScheduledActionDbAdapter;
import org.gnucash.android.db.SplitsDbAdapter;
import org.gnucash.android.db.TransactionsDbAdapter;
import org.gnucash.android.model.Commodity;
import org.gnucash.android.service.SchedulerService;

import java.util.Currency;
Expand Down Expand Up @@ -122,6 +123,8 @@ public void onCreate(){
mScheduledActionDbAdapter = new ScheduledActionDbAdapter(mDb);
mCommoditiesDbAdapter = new CommoditiesDbAdapter(mDb);
mPricesDbAdapter = new PricesDbAdapter(mDb);

Commodity.DEFAULT_COMMODITY = mCommoditiesDbAdapter.getCommodity(getDefaultCurrencyCode());
}

public static AccountsDbAdapter getAccountsDbAdapter() {
Expand Down Expand Up @@ -212,6 +215,15 @@ public static String getDefaultCurrencyCode(){
return currencyCode;
}

/**
* Returns the default commodity
* @return Default commodity of application
* @see #getDefaultCurrencyCode()
*/
public static Commodity getDefaultCommodity(){
return Commodity.DEFAULT_COMMODITY;
}

/**
* Returns the default locale which is used for currencies, while handling special cases for
* locales which are not supported for currency such as en_GB
Expand Down
Loading

0 comments on commit bbe3e2d

Please sign in to comment.