From 244a779d7ae4cdcf932d6da5f807401655c3a294 Mon Sep 17 00:00:00 2001 From: Derek Atkins Date: Mon, 24 Dec 2007 20:28:02 +0000 Subject: [PATCH] Make sure to properly parent auto-created accounts. Make sure to properly set account commodity. Make sure a currency sub-account doesn't already exist before creating one. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16715 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/gnome-utils/dialog-book-close.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/gnome-utils/dialog-book-close.c b/src/gnome-utils/dialog-book-close.c index fc692009e0c..b829d8d09bb 100644 --- a/src/gnome-utils/dialog-book-close.c +++ b/src/gnome-utils/dialog-book-close.c @@ -167,14 +167,26 @@ static void finish_txn_cb(gnc_commodity* cmdty, acc = cacb->base_acct; else { - acc = xaccMallocAccount(cacb->cbw->book); - xaccAccountBeginEdit(acc); - xaccAccountSetType(acc, ACCT_TYPE_EQUITY); - xaccAccountSetName(acc, gnc_commodity_get_mnemonic(cmdty)); - xaccAccountSetDescription(acc, gnc_commodity_get_mnemonic(cmdty)); - xaccAccountCommitEdit(acc); + /* See if we already have an account by that name */ + acc = gnc_account_lookup_by_name(cacb->base_acct, + gnc_commodity_get_mnemonic(cmdty)); + + /* If not, then create one */ + if (!acc) + { + acc = xaccMallocAccount(cacb->cbw->book); + xaccAccountBeginEdit(acc); + xaccAccountSetType(acc, ACCT_TYPE_EQUITY); + xaccAccountSetName(acc, gnc_commodity_get_mnemonic(cmdty)); + xaccAccountSetDescription(acc, gnc_commodity_get_mnemonic(cmdty)); + xaccAccountSetCommodity(acc, cmdty); + gnc_account_append_child(cacb->base_acct, acc); + xaccAccountCommitEdit(acc); + } } + /* Make sure the account exists and is of the correct commodity */ g_assert(acc); + g_assert(gnc_commodity_equal(cmdty, xaccAccountGetCommodity(acc))); /* Create the split for the Equity account to balance out * all the accounts of this. Use the "total".