Skip to content

Commit 2ce1769

Browse files
committed
Account Currency edit restriction
1 parent 0ac4f53 commit 2ce1769

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.text.TextUtils;
2626

2727
import android.util.Log;
28+
import android.support.annotation.NonNull;
2829
import org.gnucash.android.R;
2930
import org.gnucash.android.app.GnuCashApplication;
3031
import org.gnucash.android.model.*;
@@ -1322,4 +1323,26 @@ public int deleteAllRecords(){
13221323
return mDb.delete(AccountEntry.TABLE_NAME, null, null);
13231324
}
13241325

1326+
public int getTransactionMaxSplitNum(@NonNull String accountUID) {
1327+
Cursor cursor = mDb.query("trans_extra_info",
1328+
new String[]{"MAX(trans_split_count)"},
1329+
"trans_acct_t_uid IN ( SELECT DISTINCT " + TransactionEntry.TABLE_NAME + "_" + TransactionEntry.COLUMN_UID +
1330+
" FROM trans_split_acct WHERE " + AccountEntry.TABLE_NAME + "_" + AccountEntry.COLUMN_UID +
1331+
" = ? )",
1332+
new String[]{accountUID},
1333+
null,
1334+
null,
1335+
null
1336+
);
1337+
try {
1338+
if (cursor.moveToFirst()) {
1339+
return (int)cursor.getLong(0);
1340+
} else {
1341+
return 0;
1342+
}
1343+
}
1344+
finally {
1345+
cursor.close();
1346+
}
1347+
}
13251348
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private void createTempView() {
164164
SplitEntry.COLUMN_AMOUNT + " ELSE - " + SplitEntry.TABLE_NAME + "_" +
165165
SplitEntry.COLUMN_AMOUNT + " END ) AS trans_acct_balance , COUNT ( DISTINCT " +
166166
AccountEntry.TABLE_NAME + "_" + AccountEntry.COLUMN_CURRENCY +
167-
" ) AS trans_currency_count FROM trans_split_acct " +
167+
" ) AS trans_currency_count , COUNT (*) AS trans_split_count FROM trans_split_acct " +
168168
" GROUP BY " + TransactionEntry.TABLE_NAME + "_" + TransactionEntry.COLUMN_UID
169169
);
170170
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import android.graphics.Color;
2828
import android.os.Bundle;
2929
import android.preference.PreferenceManager;
30+
import android.support.annotation.NonNull;
31+
import android.support.annotation.Nullable;
3032
import android.support.v4.app.FragmentManager;
3133
import android.support.v4.widget.SimpleCursorAdapter;
3234
import android.text.TextUtils;
@@ -351,6 +353,11 @@ private void initializeViewsWithAccount(Account account){
351353
String currencyCode = account.getCurrency().getCurrencyCode();
352354
setSelectedCurrency(currencyCode);
353355

356+
if (mAccountsDbAdapter.getTransactionMaxSplitNum(mAccount.getUID()) > 1)
357+
{
358+
mCurrencySpinner.setEnabled(false);
359+
}
360+
354361
mNameEditText.setText(account.getName());
355362

356363
if (mUseDoubleEntry) {

0 commit comments

Comments
 (0)