gnucash master: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Fri Aug 22 19:45:12 EDT 2014


Updated	 via  https://github.com/Gnucash/gnucash/commit/dd10aab5 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/3f8718ea (commit)
	 via  https://github.com/Gnucash/gnucash/commit/bad092a4 (commit)
	from  https://github.com/Gnucash/gnucash/commit/1134d64a (commit)



commit dd10aab53a3fde04f05fe6399496b36e625b4c37
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Jul 31 12:00:06 2014 -0700

    Balance ENTER with a LEAVE for all exit points.
    
    For xaccLotFill and xaccLotScrubDoubleBalance, anyway.

diff --git a/src/engine/Scrub2.c b/src/engine/Scrub2.c
index d938cae..4522183 100644
--- a/src/engine/Scrub2.c
+++ b/src/engine/Scrub2.c
@@ -106,14 +106,28 @@ xaccLotFill (GNCLot *lot)
     ENTER ("(lot=%s, acc=%s)", gnc_lot_get_title(lot), xaccAccountGetName(acc));
 
     /* If balance already zero, we have nothing to do. */
-    if (gnc_lot_is_closed (lot)) return;
-
+    if (gnc_lot_is_closed (lot))
+    {
+	LEAVE ("Lot Closed (lot=%s, acc=%s)", gnc_lot_get_title(lot),
+	       xaccAccountGetName(acc));
+	return;
+    }
     split = pcy->PolicyGetSplit (pcy, lot);
-    if (!split) return;   /* Handle the common case */
+    if (!split)
+    {
+	LEAVE ("No Split (lot=%s, acc=%s)", gnc_lot_get_title(lot),
+	       xaccAccountGetName(acc));
+	return;   /* Handle the common case */
+    }
 
     /* Reject voided transactions */
     if (gnc_numeric_zero_p(split->amount) &&
-            xaccTransGetVoidStatus(split->parent)) return;
+            xaccTransGetVoidStatus(split->parent))
+    {
+	LEAVE ("Voided transaction (lot=%s, acc=%s)",
+	       gnc_lot_get_title(lot), xaccAccountGetName(acc));
+	return;
+    }
 
     xaccAccountBeginEdit (acc);
 
@@ -166,7 +180,11 @@ xaccLotScrubDoubleBalance (GNCLot *lot)
     }
 
     /* We double-check only closed lots */
-    if (FALSE == gnc_lot_is_closed (lot)) return;
+    if (FALSE == gnc_lot_is_closed (lot))
+    {
+	LEAVE ("lot=%s is closed", gnc_lot_get_title(lot));
+	return;
+    }
 
     for (snode = gnc_lot_get_split_list(lot); snode; snode = snode->next)
     {

commit 3f8718ea3bbbb980f6e18949e058fc3919e06925
Author: John Ralls <jralls at ceridwen.us>
Date:   Fri Aug 1 16:21:01 2014 -0700

    Divide the value by the rate to get the amount.
    
    Avoids overflowing the amount and is anyway much more realistic:
    Value = Amount * price, so a large "rate" means a small price. Since
    get_random_rate() is biased to producing large rates (denom is fixed
    at 100), it was effectively testing infinitesimal prices.

diff --git a/src/engine/test-core/test-engine-stuff.c b/src/engine/test-core/test-engine-stuff.c
index 7e5b57e..977f221 100644
--- a/src/engine/test-core/test-engine-stuff.c
+++ b/src/engine/test-core/test-engine-stuff.c
@@ -475,6 +475,9 @@ get_random_gnc_numeric(void)
     return gnc_numeric_create(numer, deno);
 }
 
+
+/* Rate here really means price or exchange rate, this is used solely
+ * to compute an amount from a randomly-created value. */
 static gnc_numeric
 get_random_rate (void)
 {
@@ -1322,11 +1325,8 @@ get_random_split(QofBook *book, Account *acct, Transaction *trn)
                                                xaccSplitGetAccount(ret)));
         do
         {
-            /* Large rates blow up xaccSplitAssignLot */
             rate = get_random_rate ();
-            amt = gnc_numeric_mul(val, rate,
-                                  GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);
-            amt = gnc_numeric_convert(amt, denom, GNC_HOW_RND_ROUND_HALF_UP);
+            amt = gnc_numeric_div(val, rate, denom, GNC_HOW_RND_ROUND_HALF_UP);
         }
         while (gnc_numeric_check(amt) != GNC_ERROR_OK);
     }

commit bad092a46d61c5e5910a4707ed38d40883751bd9
Author: John Ralls <jralls at ceridwen.us>
Date:   Fri Aug 1 16:15:52 2014 -0700

    Prevent assigning capital gains splits to lots.
    
    They're generated by lots, and when xaccSplitComputeCapGains sees one it grabs the originating lot which naturally doesn't balance.

diff --git a/src/engine/cap-gains.c b/src/engine/cap-gains.c
index b7ea3f1..a40d6ef 100644
--- a/src/engine/cap-gains.c
+++ b/src/engine/cap-gains.c
@@ -93,6 +93,7 @@ xaccAccountHasTrades (const Account *acc)
     {
         Split *s = node->data;
         Transaction *t = s->parent;
+	if (s->gains == GAINS_STATUS_GAINS) continue;
         if (acc_comm != t->common_currency) return TRUE;
     }
 
@@ -444,6 +445,8 @@ xaccSplitAssign (Split *split)
      * have lots, we are done.
      */
     if (split->lot) return FALSE;
+    g_assert (split->gains == GAINS_STATUS_UNKNOWN ||
+	      (split->gains & GAINS_STATUS_GAINS) == FALSE);
     acc = split->acc;
     if (!xaccAccountHasTrades (acc))
         return FALSE;



Summary of changes:
 src/engine/Scrub2.c                      | 28 +++++++++++++++++++++++-----
 src/engine/cap-gains.c                   |  3 +++
 src/engine/test-core/test-engine-stuff.c |  8 ++++----
 3 files changed, 30 insertions(+), 9 deletions(-)



More information about the gnucash-changes mailing list