[Gnucash-changes] r13874 - gnucash/trunk/src/engine - When deleting
an Account, also delete any Splits that are set to be
Chris Shoemaker
chris at cvs.gnucash.org
Fri Apr 28 22:17:17 EDT 2006
Author: chris
Date: 2006-04-28 22:17:14 -0400 (Fri, 28 Apr 2006)
New Revision: 13874
Trac: http://svn.gnucash.org/trac/changeset/13874
Modified:
gnucash/trunk/src/engine/Account.c
gnucash/trunk/src/engine/AccountP.h
Log:
When deleting an Account, also delete any Splits that are set to be
added to the Account if their open Transaction is commited.
Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c 2006-04-29 02:04:57 UTC (rev 13873)
+++ gnucash/trunk/src/engine/Account.c 2006-04-29 02:17:14 UTC (rev 13874)
@@ -333,6 +333,17 @@
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 @@
if (acc->inst.do_free)
{
GList *lp, *slist;
+ QofCollection *col;
acc->inst.editlevel++;
@@ -360,6 +372,7 @@
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 @@
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)
{
Modified: gnucash/trunk/src/engine/AccountP.h
===================================================================
--- gnucash/trunk/src/engine/AccountP.h 2006-04-29 02:04:57 UTC (rev 13873)
+++ gnucash/trunk/src/engine/AccountP.h 2006-04-29 02:17:14 UTC (rev 13874)
@@ -67,7 +67,7 @@
* 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;
More information about the gnucash-changes
mailing list