[Gnucash-changes] add check -- cap gains not possible is value and amount are in the same

Linas Vepstas linas at cvs.gnucash.org
Tue Jul 6 10:39:19 EDT 2004


Log Message:
-----------
add check -- cap gains not possible is value and amount are in the same
currency

Modified Files:
--------------
    gnucash/src/engine:
        cap-gains.c

Revision Data
-------------
Index: cap-gains.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/cap-gains.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -Lsrc/engine/cap-gains.c -Lsrc/engine/cap-gains.c -u -r1.28 -r1.29
--- src/engine/cap-gains.c
+++ src/engine/cap-gains.c
@@ -192,7 +192,8 @@
       
    lot = xaccAccountFindOpenLot (acc, sign, currency,
                    10000000LL * ((long long) LONG_MAX), earliest_pred);
-   LEAVE ("found lot=%p %s", lot, gnc_lot_get_title (lot));
+   LEAVE ("found lot=%p %s baln=%s", lot, gnc_lot_get_title (lot),
+               gnc_num_dbg_to_string(gnc_lot_get_balance(lot)));
    return lot;
 }
 
@@ -488,7 +489,7 @@
       val_a = gnc_numeric_mul (frac, val_tot, 
                         gnc_numeric_denom(val_tot), 
                         GNC_HOW_RND_ROUND| GNC_HOW_DENOM_EXACT);
-
+ 
       val_b = gnc_numeric_sub_fixed (val_tot, val_a);
       if (gnc_numeric_check(val_a))
       {
@@ -608,7 +609,8 @@
     */
    while (split)
    {
-     PINFO ("have split amount=%s", gnc_num_dbg_to_string (split->amount));
+     PINFO ("have split %p amount=%s", split, 
+             gnc_num_dbg_to_string (split->amount));
      split->gains |= GAINS_STATUS_VDIRTY;
      lot = pcy->PolicyGetLot (pcy, split);
      if (!lot)
@@ -674,6 +676,16 @@
 
    /* Make sure the status flags and pointers are initialized */
    if (GAINS_STATUS_UNKNOWN == split->gains) xaccSplitDetermineGainStatus(split);
+
+   /* Not possible to have gains if the transaction currency and 
+    * account commodity are identical. */
+   if (gnc_commodity_equal (currency,
+                            xaccAccountGetCommodity(split->acc)))
+   {
+      LEAVE ("Currency transfer, gains not possible, returning.");
+      return;
+   }
+
    if (pcy->PolicyIsOpeningSplit (pcy, lot, split))
    {
 #if MOVE_THIS_TO_A_DATA_INTEGRITY_SCRUBBER 
@@ -928,6 +940,7 @@
           * just in case someone screwed with it! */
          if (FALSE == gnc_commodity_equiv(currency,trans->common_currency))
          {
+            PWARN ("Resetting the transaction currency!");
             xaccTransSetCurrency (trans, currency);
          }
       }
@@ -955,7 +968,7 @@
 
       xaccTransCommitEdit (trans);
    }
-   LEAVE ("(lot=%s)", kvp_frame_get_string (gnc_lot_get_slots (lot), "/title"));
+   LEAVE ("(lot=%s)", gnc_lot_get_title(lot));
 }
 
 /* ============================================================== */


More information about the gnucash-changes mailing list