[Gnucash-changes] r13460 - gnucash/trunk/src/engine - Move one data-validation function from Scrub.c into Transaction.c

Chris Shoemaker chris at cvs.gnucash.org
Fri Mar 3 19:10:45 EST 2006


Author: chris
Date: 2006-03-03 19:10:44 -0500 (Fri, 03 Mar 2006)
New Revision: 13460
Trac: http://svn.gnucash.org/trac/changeset/13460

Modified:
   gnucash/trunk/src/engine/Scrub.c
Log:
   Move one data-validation function from Scrub.c into Transaction.c
   One simplification in xaccTransScrubImbalance() to always find the root
   AccountGroup from the Transaction's book.



Modified: gnucash/trunk/src/engine/Scrub.c
===================================================================
--- gnucash/trunk/src/engine/Scrub.c	2006-03-04 00:10:12 UTC (rev 13459)
+++ gnucash/trunk/src/engine/Scrub.c	2006-03-04 00:10:44 UTC (rev 13460)
@@ -103,9 +103,7 @@
     orph = xaccScrubUtilityGetOrMakeAccount (root, trans->common_currency, _("Orphan"));
     if (!orph) continue;
 
-    xaccAccountBeginEdit (orph);
-    xaccAccountInsertSplit (orph, split);
-    xaccAccountCommitEdit (orph);
+    xaccSplitSetAccount(split, orph);
   }
 }
 
@@ -196,27 +194,6 @@
 }
 
 void
-xaccTransScrubSplits (Transaction *trans)
-{
-  gnc_commodity *currency;
-  GList *node;
-
-  if (!trans) return;
-
-  /* The split scrub expects the transaction to have a currency! */
-  currency = xaccTransGetCurrency (trans);
-  if (!currency) 
-  {
-    PERR ("Transaction doesn't have a currency!");
-  }
-
-  for (node = trans->splits; node; node = node->next)
-  {
-    xaccSplitScrub (node->data);
-  }
-}
-
-void
 xaccSplitScrub (Split *split)
 {
   Account *account;
@@ -233,7 +210,7 @@
 
   account = xaccSplitGetAccount (split);
 
-  /* If theres no account, this split is an orphan.
+  /* If there's no account, this split is an orphan.
    * We need to fix that first, before proceeding.
    */
   if (!account)
@@ -421,48 +398,30 @@
 
 void
 xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
-                         Account *parent)
+                         Account *account)
 {
   Split *balance_split = NULL;
-  QofBook *book = NULL;
   gnc_numeric imbalance;
-  Account *account;
-  SplitList *node, *slist;
 
   if (!trans) return;
 
   ENTER ("()");
-  xaccTransScrubSplits (trans);
 
   /* If the transaction is balanced, nothing more to do */
   imbalance = xaccTransGetImbalance (trans);
   if (gnc_numeric_zero_p (imbalance)) return;
 
-  slist = xaccTransGetSplitList (trans);
-  if (!slist) return;
+  xaccTransBeginEdit(trans);
+  xaccTransScrubSplits (trans);
+  xaccTransCommitEdit(trans);
 
-  if (!parent)
+  if (!account)
   {
     if (!root) 
-    { 
-       Split *s = slist->data; 
-       if (NULL == s->acc)
-       {
-          /* This should never occur, since xaccTransScrubSplits()
-           * above should have fixed things up.  */
-          PERR ("Split is not assigned to any account");
-       }
-       root = xaccAccountGetRoot (s->acc);
+    {
+       root = xaccGetAccountGroup (xaccTransGetBook (trans));
        if (NULL == root)
        {
-          /* This should never occur, accounts are always 
-           * in an account group */
-          PERR ("Can't find root account");
-          book = xaccTransGetBook (trans);
-          root = xaccGetAccountGroup (book);
-       }
-       if (NULL == root)
-       {
           /* This can't occur, things should be in books */
           PERR ("Bad data corruption, no root account in book");
           return;
@@ -470,37 +429,23 @@
     }
     account = xaccScrubUtilityGetOrMakeAccount (root, 
         trans->common_currency, _("Imbalance"));
-  }
-  else
-  {
-    account = parent;
-  }
-
-  if (!account) 
-  {
-      PERR ("Can't get balancing account");
-      return;
-  }
-
-  for (node = slist; node; node = node->next)
-  {
-    Split *split = node->data;
-
-    if (xaccSplitGetAccount (split) == account)
-    {
-      balance_split = split;
-      break;
+    if (!account) {
+        PERR ("Can't get balancing account");
+        return;
     }
   }
 
+  balance_split = xaccTransFindSplitByAccount(trans, account);
+
   /* Put split into account before setting split value */
   if (!balance_split)
   {
     balance_split = xaccMallocSplit (trans->inst.book);
 
-    xaccAccountBeginEdit (account);
-    xaccAccountInsertSplit (account, balance_split);
-    xaccAccountCommitEdit (account);
+    xaccTransBeginEdit (trans);
+    xaccSplitSetParent(balance_split, trans);
+    xaccSplitSetAccount(balance_split, account);
+    xaccTransCommitEdit (trans);
   }
 
   PINFO ("unbalanced transaction");
@@ -530,7 +475,6 @@
       xaccSplitSetAmount (balance_split, new_value);
     }
 
-    xaccTransAppendSplit (trans, balance_split);
     xaccSplitScrub (balance_split);
     xaccTransCommitEdit (trans);
   }
@@ -666,7 +610,7 @@
 
   /* If there are any orphaned splits in a transaction, then the 
    * this routine will fail.  Therefore, we want to make sure that
-   * tehre are no orphans (splits without parent account).
+   * there are no orphans (splits without parent account).
    */
   xaccTransScrubOrphans (trans);
 



More information about the gnucash-changes mailing list