Skip to content

Commit

Permalink
Fix QIF export sometimes exports all transactions
Browse files Browse the repository at this point in the history
This is due to the import still in progress while the last export time is set.
Now we query the database to get the last export time (instead of using current time) which ensures that the import database transaction must have completed first.

Fixes codinguser#444
  • Loading branch information
codinguser committed Dec 1, 2015
1 parent c2df4e5 commit 13ef64a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Change Log
===============================================================================
Version 2.0.4 *(2015-12-xx)*
----------------------------
* Fixed: Transaction export time not always working reliably
* Fixed: Renaming account causes transactions to be deleted


Version 2.0.3 *(2015-11-21)*
----------------------------
* Fixed: Unable to enter decimal amounts in split editor
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'io.fabric'

def versionMajor = 2
def versionMinor = 0
def versionPatch = 3
def versionPatch = 4
def versionBuild = 0

def buildTime() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.gnucash.android.model.Split;
import org.gnucash.android.model.Transaction;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -633,6 +634,22 @@ public long getTimestampOfLatestTransaction(AccountType type, String currencyCod
return getTimestamp("MAX", type, currencyCode);
}

/**
* Returns the most recent `modified_at` timestamp of non-template transactions in the database
* @return Last moodified time in milliseconds or null if no such transactions exist
*/
public Timestamp getTimestampOfLastModification(){
Cursor cursor = mDb.query(TransactionEntry.TABLE_NAME,
new String[]{"MAX(" + TransactionEntry.COLUMN_MODIFIED_AT + ")"},
TransactionEntry.COLUMN_TEMPLATE + " = 0", null, null, null, null);
Timestamp timestamp = null;
if (cursor.moveToNext()){
String timeString = cursor.getString(0);
timestamp = Timestamp.valueOf(timeString);
}
return timestamp;
}

/**
* Returns the earliest or latest timestamp of transactions for a specific account type and currency
* @param mod Mode (either MAX or MIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.util.Log;

import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.db.TransactionsDbAdapter;
import org.gnucash.android.export.Exporter;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -93,8 +94,12 @@ public static void parse(InputStream gncXmlInputStream) throws ParserConfigurati
xr.parse(new InputSource(bos));
long endTime = System.nanoTime();

String timeStamp = new Timestamp(System.currentTimeMillis()).toString();
PreferenceManager.getDefaultSharedPreferences(GnuCashApplication.getAppContext()).edit().putString(Exporter.PREF_LAST_EXPORT_TIME, timeStamp).apply();

Timestamp timeStamp = TransactionsDbAdapter.getInstance().getTimestampOfLastModification();
PreferenceManager.getDefaultSharedPreferences(GnuCashApplication.getAppContext())
.edit()
.putString(Exporter.PREF_LAST_EXPORT_TIME, timeStamp.toString())
.apply();

Log.d(GncXmlImporter.class.getSimpleName(), String.format("%d ns spent on importing the file", endTime-startTime));
}
Expand Down

0 comments on commit 13ef64a

Please sign in to comment.