Skip to content

Commit 0f121ed

Browse files
committed
Update full name when account name changed
1 parent 62eab82 commit 0f121ed

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,10 @@ private void loadParentAccountList(AccountType accountType){
554554

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

563563
//if we are reloading the list, close the previous cursor first
@@ -684,6 +684,7 @@ public void onDestroy() {
684684
private void saveAccount() {
685685
// accounts to update, in case we're updating full names of a sub account tree
686686
ArrayList<Account> accountsToUpdate = new ArrayList<Account>();
687+
boolean nameChanged = false;
687688
if (mAccount == null){
688689
String name = getEnteredName();
689690
if (name == null || name.length() == 0){
@@ -694,8 +695,10 @@ private void saveAccount() {
694695
}
695696
mAccount = new Account(getEnteredName());
696697
}
697-
else
698-
mAccount.setName(getEnteredName());
698+
else {
699+
nameChanged = !mAccount.getName().equals(getEnteredName());
700+
mAccount.setName(getEnteredName());
701+
}
699702

700703
String curCode = mCurrencyCodes.get(mCurrencySpinner
701704
.getSelectedItemPosition());
@@ -730,8 +733,8 @@ private void saveAccount() {
730733

731734
long parentAccountId = mAccountsDbAdapter.getID(mParentAccountUID);
732735
// update full names
733-
if (mDescendantAccountUIDs == null || newParentAccountId != parentAccountId) {
734-
// new Account or parent account changed
736+
if (nameChanged || mDescendantAccountUIDs == null || newParentAccountId != parentAccountId) {
737+
// current account name changed or new Account or parent account changed
735738
String newAccountFullName;
736739
if (newParentAccountId == mRootAccountId){
737740
newAccountFullName = mAccount.getName();
@@ -742,8 +745,8 @@ private void saveAccount() {
742745
}
743746
mAccount.setFullName(newAccountFullName);
744747
if (mDescendantAccountUIDs != null) {
745-
// modifying existing account
746-
if (parentAccountId != newParentAccountId && mDescendantAccountUIDs.size() > 0) {
748+
// modifying existing account, e.t. name changed and/or parent changed
749+
if ((nameChanged || parentAccountId != newParentAccountId) && mDescendantAccountUIDs.size() > 0) {
747750
// parent change, update all full names of descent accounts
748751
accountsToUpdate.addAll(mAccountsDbAdapter.getSimpleAccountList(
749752
DatabaseSchema.AccountEntry.COLUMN_UID + " IN ('" +

0 commit comments

Comments
 (0)