r16715 - gnucash/trunk/src/gnome-utils - Make sure to properly parent auto-created accounts.
Derek Atkins
warlord at cvs.gnucash.org
Mon Dec 24 15:28:03 EST 2007
Author: warlord
Date: 2007-12-24 15:28:02 -0500 (Mon, 24 Dec 2007)
New Revision: 16715
Trac: http://svn.gnucash.org/trac/changeset/16715
Modified:
gnucash/trunk/src/gnome-utils/dialog-book-close.c
Log:
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.
Modified: gnucash/trunk/src/gnome-utils/dialog-book-close.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-book-close.c 2007-12-24 04:48:49 UTC (rev 16714)
+++ gnucash/trunk/src/gnome-utils/dialog-book-close.c 2007-12-24 20:28:02 UTC (rev 16715)
@@ -167,14 +167,26 @@
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".
More information about the gnucash-changes
mailing list