Skip to content

Commit

Permalink
Merge pull request codinguser#262 from fefe982/fix-updateacctname
Browse files Browse the repository at this point in the history
Update full name when account name changed
  • Loading branch information
codinguser committed Nov 12, 2014
2 parents bc84003 + 0f121ed commit 8af589b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions app/src/org/gnucash/android/ui/account/AccountFormFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,10 @@ private void loadParentAccountList(AccountType accountType){

if (mAccount != null){ //if editing an account
mDescendantAccountUIDs = mAccountsDbAdapter.getDescendantAccountUIDs(mAccount.getUID(), null, null);
mDescendantAccountUIDs.add(mAccountUID); //cannot set self as parent
// limit cyclic account hierarchies.
condition += " AND (" + DatabaseSchema.AccountEntry.COLUMN_PARENT_ACCOUNT_UID + " IS NULL "
+ " OR " + DatabaseSchema.AccountEntry.COLUMN_UID + " NOT IN ( '" + TextUtils.join("','", mDescendantAccountUIDs) + "' ) )";
+ " OR " + DatabaseSchema.AccountEntry.COLUMN_UID + " NOT IN ( '"
+ TextUtils.join("','", mDescendantAccountUIDs) + "','" + mAccountUID + "' ) )";
}

//if we are reloading the list, close the previous cursor first
Expand Down Expand Up @@ -684,6 +684,7 @@ public void onDestroy() {
private void saveAccount() {
// accounts to update, in case we're updating full names of a sub account tree
ArrayList<Account> accountsToUpdate = new ArrayList<Account>();
boolean nameChanged = false;
if (mAccount == null){
String name = getEnteredName();
if (name == null || name.length() == 0){
Expand All @@ -694,8 +695,10 @@ private void saveAccount() {
}
mAccount = new Account(getEnteredName());
}
else
mAccount.setName(getEnteredName());
else {
nameChanged = !mAccount.getName().equals(getEnteredName());
mAccount.setName(getEnteredName());
}

String curCode = mCurrencyCodes.get(mCurrencySpinner
.getSelectedItemPosition());
Expand Down Expand Up @@ -730,8 +733,8 @@ private void saveAccount() {

long parentAccountId = mAccountsDbAdapter.getID(mParentAccountUID);
// update full names
if (mDescendantAccountUIDs == null || newParentAccountId != parentAccountId) {
// new Account or parent account changed
if (nameChanged || mDescendantAccountUIDs == null || newParentAccountId != parentAccountId) {
// current account name changed or new Account or parent account changed
String newAccountFullName;
if (newParentAccountId == mRootAccountId){
newAccountFullName = mAccount.getName();
Expand All @@ -742,8 +745,8 @@ private void saveAccount() {
}
mAccount.setFullName(newAccountFullName);
if (mDescendantAccountUIDs != null) {
// modifying existing account
if (parentAccountId != newParentAccountId && mDescendantAccountUIDs.size() > 0) {
// modifying existing account, e.t. name changed and/or parent changed
if ((nameChanged || parentAccountId != newParentAccountId) && mDescendantAccountUIDs.size() > 0) {
// parent change, update all full names of descent accounts
accountsToUpdate.addAll(mAccountsDbAdapter.getSimpleAccountList(
DatabaseSchema.AccountEntry.COLUMN_UID + " IN ('" +
Expand Down

0 comments on commit 8af589b

Please sign in to comment.