From 7cdd1d7751d675e5a80c4ac963594bee0ad78318 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Wed, 2 Jan 2002 19:03:05 +0000 Subject: [PATCH] book/acct-period related bugfixes git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6484 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Account.c | 16 ++++++---------- src/engine/Group.c | 10 ++++++++-- src/engine/Period.c | 12 ++++++++++-- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/engine/Account.c b/src/engine/Account.c index b6264e6e42..4d3f366e1a 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -145,7 +145,9 @@ xaccCloneAccountSimple(const Account *from, GNCBook *book) xaccInitAccount (ret, book); - xaccAccountBeginEdit (ret); + /* Do not Begin/CommitEdit() here; give the caller + * a chance to fix things up, and let them do it. + * Also let caller issue the generate_event (EVENT_CREATE) */ ret->type = from->type; ret->accountName = g_strdup(from->accountName); @@ -158,10 +160,6 @@ xaccCloneAccountSimple(const Account *from, GNCBook *book) ret->commodity_scu = from->commodity_scu; ret->core_dirty = TRUE; - gnc_engine_generate_event (&ret->guid, GNC_EVENT_CREATE); - - xaccAccountCommitEdit (ret); - LEAVE (" "); return ret; } @@ -181,7 +179,9 @@ xaccCloneAccount (const Account *from, GNCBook *book) now = time(0); xaccInitAccount (ret, book); - xaccAccountBeginEdit (ret); + /* Do not Begin/CommitEdit() here; give the caller + * a chance to fix things up, and let them do it. + * Also let caller issue the generate_event (EVENT_CREATE) */ ret->type = from->type; ret->accountName = g_strdup(from->accountName); @@ -198,10 +198,6 @@ xaccCloneAccount (const Account *from, GNCBook *book) gnc_kvp_gemini (ret->kvp_data, &from->guid, &from->book->guid, now); gnc_kvp_gemini (from->kvp_data, &ret->guid, &book->guid, now); - gnc_engine_generate_event (&ret->guid, GNC_EVENT_CREATE); - - xaccAccountCommitEdit (ret); - LEAVE (" "); return ret; } diff --git a/src/engine/Group.c b/src/engine/Group.c index 1e6a115b03..aad1e5985e 100644 --- a/src/engine/Group.c +++ b/src/engine/Group.c @@ -699,7 +699,7 @@ xaccGroupInsertAccount (AccountGroup *grp, Account *acc) // xxxxxxxxxxxxxxxxxxxxxxx /* hack alert -- this implementation is not exactly correct. * If the entity tables are not identical, then the 'from' book - * will have a different backend than the 'to' book. This means + * may have a different backend than the 'to' book. This means * that we should get the 'from' backend to destroy this account, * and the 'to' backend to save it. Right now, this is broken. * @@ -784,15 +784,21 @@ xaccGroupCopyGroup (AccountGroup *to, AccountGroup *from) to_acc = xaccCloneAccount (from_acc, to->book); xaccAccountBeginEdit (to_acc); - to->accounts = g_list_append (to->accounts, to_acc); + to->accounts = g_list_insert_sorted (to->accounts, to_acc, + group_sort_helper); + + to_acc->parent = to; + to_acc->core_dirty = TRUE; /* copy child accounts too. */ if (from_acc->children) { to_acc->children = xaccMallocAccountGroup (to->book); + to_acc->children->parent = to_acc; xaccGroupCopyGroup (to_acc->children, from_acc->children); } xaccAccountCommitEdit (to_acc); + gnc_engine_generate_event (&to_acc->guid, GNC_EVENT_CREATE); /* make sure that we have a symmetric, uniform number of * begin-edits, so that subsequent GroupCommitEdit's diff --git a/src/engine/Period.c b/src/engine/Period.c index 76c07005e9..59d4680635 100644 --- a/src/engine/Period.c +++ b/src/engine/Period.c @@ -104,10 +104,18 @@ gnc_book_insert_trans (GNCBook *book, Transaction *trans) if (!trans || !book) return; - /* if this is the same book, its a no-op. */ + /* If this is the same book, its a no-op. */ if (trans->book == book) return; - /* fiddle the transaction into place in the new book */ + /* If the old and new book don't share backends, then clobber-copy; + * i.e. destroy it in one backend, create it in another. */ + if (book->backend != trans->book->backend) + { + gnc_book_insert_trans_clobber (book, trans); + return; + } + + /* Fiddle the transaction into place in the new book */ xaccTransBeginEdit (trans); xaccRemoveEntity (trans->book->entity_table, &trans->guid);