mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug #569735: Don't create a new nested template root account when a file is opened
Whenever an XML file is opened, Gnucash creates a new template root account and makes the old one a child of it. My main accounts file had them nested over 540 deep before I got annoyed enough to fix this. The problem is that sxtg_book_begin creates a root account when the book is opened. Then add_template_transaction_local tries to replace this new root account with the one read from the file. However the code that does this is rather badly broken and the result is that the one read from the file becomes a child of the one created in sxtg_book_begin. This patch avoids creating any more nested root accounts, but it doesn't get rid of the ones that are already there. This is slightly more tricky than just deleting them since, although most of them have no children (other than the next root account), some do. Accounts created for template transactions will be children of whatever root account happens to be at the top of the tree then. As the file is saved and reopened, this will get pushed down into the tree of accounts. In my case about 5 of the 540 or so root accounts had other children. Patch by Mike Alexander. BP git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17868 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
f5f0ecf016
commit
35e6699d41
@ -285,19 +285,8 @@ add_template_transaction_local( sixtp_gdv2 *data,
|
||||
/* . transactions in those accounts. */
|
||||
for ( n = txd->accts; n; n = n->next ) {
|
||||
if ( gnc_account_get_parent( (Account*)n->data ) == NULL ) {
|
||||
/* remove the gnc_book_init-created account of the same name */
|
||||
acctRoot = gnc_book_get_template_root(book);
|
||||
tmpAcct = gnc_account_lookup_by_name( acctRoot,
|
||||
xaccAccountGetName( (Account*)n->data ) );
|
||||
if ( tmpAcct != NULL ) {
|
||||
/* XXX hack alert FIXME .... Should this be 'Remove', or 'Destroy'?
|
||||
* If we just remove, then this seems to be a memory leak to me, since
|
||||
* it is never reparented. Shouldn't it be a Destroy ???
|
||||
*/
|
||||
gnc_account_remove_child( acctRoot, tmpAcct );
|
||||
}
|
||||
|
||||
gnc_account_append_child( acctRoot, (Account*)n->data );
|
||||
/* replace the gnc_book_init-created root account */
|
||||
gnc_book_set_template_root(book, (Account *)n->data);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user