From 4bc2e2e86df9df0acb9d922f56af7856a8334d33 Mon Sep 17 00:00:00 2001 From: Chris Shoemaker Date: Sat, 29 Apr 2006 02:17:14 +0000 Subject: [PATCH] When deleting an Account, also delete any Splits that are set to be added to the Account if their open Transaction is commited. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13874 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Account.c | 17 ++++++++++++++++- src/engine/AccountP.h | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/engine/Account.c b/src/engine/Account.c index 0d26e6bd3d..b4781a5619 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -333,6 +333,17 @@ static inline void acc_free (QofInstance *inst) xaccFreeAccount(acc); } +static void +destroy_pending_splits_for_account(QofEntity *ent, gpointer acc) +{ + Transaction *trans = (Transaction *) ent; + Split *split; + + if (xaccTransIsOpen(trans)) + while ((split = xaccTransFindSplitByAccount(trans, acc))) + xaccSplitDestroy(split); +} + void xaccAccountCommitEdit (Account *acc) { @@ -344,6 +355,7 @@ xaccAccountCommitEdit (Account *acc) if (acc->inst.do_free) { GList *lp, *slist; + QofCollection *col; acc->inst.editlevel++; @@ -360,6 +372,7 @@ xaccAccountCommitEdit (Account *acc) Split *s = lp->data; xaccSplitDestroy (s); } + g_list_free(slist); /* It turns out there's a case where this assertion does not hold: When the user tries to delete an Imbalance account, while also deleting all the splits in it. The splits will just get @@ -368,7 +381,9 @@ xaccAccountCommitEdit (Account *acc) g_assert(acc->splits == NULL || qof_book_shutting_down(acc->inst.book)); */ - g_list_free(slist); + col = qof_book_get_collection(acc->inst.book, GNC_ID_TRANS); + qof_collection_foreach(col, destroy_pending_splits_for_account, acc); + /* the lots should be empty by now */ for (lp=acc->lots; lp; lp=lp->next) { diff --git a/src/engine/AccountP.h b/src/engine/AccountP.h index 56c0cdab26..fd9f0b531e 100644 --- a/src/engine/AccountP.h +++ b/src/engine/AccountP.h @@ -67,7 +67,7 @@ struct account_s * It is intended to be reporting code that is a synonym for the * accountName. Typically, it will be a numeric value that follows * the numbering assignments commonly used by accountants, such - * as 100, 200 or 600 for top-level * accounts, and 101, 102.. etc. + * as 100, 200 or 600 for top-level accounts, and 101, 102.. etc. * for detail accounts. */ char *accountCode;