From 97e65c9d7422ec2854ba4aa12f1194dfd1ea0310 Mon Sep 17 00:00:00 2001 From: David Hampton Date: Wed, 23 Aug 2006 03:17:29 +0000 Subject: [PATCH] Make sure the root account exists when the code asks for it. This works both for reading a new file and a user performing File->New->New File. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/branches/remove-group@14715 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 5 +++++ src/backend/file/io-gncxml-v2.c | 7 ------- src/engine/Account.c | 7 ++++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 69e9080a19..ebe303e324 100644 --- a/ChangeLog +++ b/ChangeLog @@ -94,6 +94,11 @@ 2006-08-20 David Hampton + * src/backend/file/io-gncxml-v2.c: + * src/engine/Account.c: Make sure the root account exists when the + code asks for it. This works both for reading a new file and a + user performing File->New->New File. + * src/gnome-utils/gnc-tree-model-account.c: Fix a mistake in the updated tree model. diff --git a/src/backend/file/io-gncxml-v2.c b/src/backend/file/io-gncxml-v2.c index 5603ab6775..0327316cb5 100644 --- a/src/backend/file/io-gncxml-v2.c +++ b/src/backend/file/io-gncxml-v2.c @@ -190,12 +190,6 @@ add_account_local(sixtp_gdv2 *data, Account *act) parent = gnc_account_get_parent(act); if (parent == NULL) { root = gnc_book_get_root_account(data->book); - if (root == NULL) { - root = gnc_account_create_root(data->book); - /* Leave the account in the edit state. It will be committed - * at the end of reading all the transactions. */ - xaccAccountBeginEdit(root); - } gnc_account_append_child(root, act); } } @@ -776,7 +770,6 @@ qof_session_load_from_xml_file_v2_full( gnc_account_foreach_descendant(root, (AccountCb) xaccAccountCommitEdit, NULL); - xaccAccountCommitEdit (root); /* start logging again */ xaccLogEnable (); diff --git a/src/engine/Account.c b/src/engine/Account.c index 639c0618de..7f0cea3edd 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -180,9 +180,14 @@ Account * gnc_book_get_root_account (QofBook *book) { QofCollection *col; + Account *root; + if (!book) return NULL; col = qof_book_get_collection (book, GNC_ID_ROOT_ACCOUNT); - return gnc_coll_get_root_account (col); + root = gnc_coll_get_root_account (col); + if (root == NULL) + root = gnc_account_create_root(book); + return root; } void