r18166 - gnucash/trunk/src/register/ledger-core - Bug #580968: Register: Keep track of the account when an exchange rate is set, and don't reset the rate unless the commodity changes. Previously the rate would be reset whenever focus left the account cell, even if the commodity hadn't changed.

Charles Day cedayiv at code.gnucash.org
Wed Jul 1 19:05:24 EDT 2009


Author: cedayiv
Date: 2009-07-01 19:05:24 -0400 (Wed, 01 Jul 2009)
New Revision: 18166
Trac: http://svn.gnucash.org/trac/changeset/18166

Modified:
   gnucash/trunk/src/register/ledger-core/split-register-control.c
   gnucash/trunk/src/register/ledger-core/split-register-p.h
Log:
Bug #580968: Register: Keep track of the account when an exchange rate is set, and don't reset the rate unless the commodity changes. Previously the rate would be reset whenever focus left the account cell, even if the commodity hadn't changed.


Modified: gnucash/trunk/src/register/ledger-core/split-register-control.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-control.c	2009-07-01 12:33:56 UTC (rev 18165)
+++ gnucash/trunk/src/register/ledger-core/split-register-control.c	2009-07-01 23:05:24 UTC (rev 18166)
@@ -246,15 +246,22 @@
     Split         *split     = gnc_split_register_get_current_split(reg);
     Account       *orig_acct = xaccSplitGetAccount(split);
     gnc_commodity *orig_com  = xaccAccountGetCommodity(orig_acct);
+    gnc_commodity *last_com  = xaccAccountGetCommodity(info->rate_account);
     gnc_commodity *new_com   = xaccAccountGetCommodity(new_acct);
 
-    if (!gnc_commodity_equal(orig_com, new_com))
+    if (gnc_commodity_equal(last_com? last_com : orig_com, new_com))
     {
-      DEBUG("Commodity now %s (originally %s). Clearing rate.",
+      DEBUG("Commodity is still %s. Leaving rate unchanged.",
+            new_com  ? gnc_commodity_get_mnemonic(new_com) : "NULL");
+    }
+    else if (!gnc_commodity_equal(orig_com, new_com))
+    {
+      DEBUG("Commodity now %s (was %s). Clearing rate.",
             new_com  ? gnc_commodity_get_mnemonic(new_com) : "NULL",
             orig_com ? gnc_commodity_get_mnemonic(orig_com) : "NULL");
 
       gnc_price_cell_set_value (rate_cell, gnc_numeric_zero());
+      info->rate_account = new_acct;
       info->rate_reset = TRUE;
     }
     else
@@ -270,12 +277,14 @@
         DEBUG("Using original rate of %s.",
               gnc_num_dbg_to_string(orig_rate));
         gnc_price_cell_set_value (rate_cell, orig_rate);
+        info->rate_account = new_acct;
         info->rate_reset = FALSE;
       }
       else
       {
         DEBUG("Can't get rate. Using zero.");
         gnc_price_cell_set_value (rate_cell, gnc_numeric_zero());
+        info->rate_account = new_acct;
         info->rate_reset = TRUE;
       }
     }
@@ -438,6 +447,7 @@
   if (old_split != new_split)
   {
     info->change_confirmed = FALSE;
+    info->rate_account = NULL;
     info->rate_reset = FALSE;
   }
 
@@ -1363,6 +1373,7 @@
   /* Set the RATE_CELL on this cursor and mark it changed */
   gnc_price_cell_set_value (rate_cell, exch_rate);
   gnc_basic_cell_set_changed (&rate_cell->cell, TRUE);
+  info->rate_account = xfer_acc;
   info->rate_reset = FALSE;
   LEAVE("set rate=%s", gnc_num_dbg_to_string(exch_rate));
   return FALSE;

Modified: gnucash/trunk/src/register/ledger-core/split-register-p.h
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-p.h	2009-07-01 12:33:56 UTC (rev 18165)
+++ gnucash/trunk/src/register/ledger-core/split-register-p.h	2009-07-01 23:05:24 UTC (rev 18166)
@@ -94,6 +94,9 @@
   /* true if the exchange rate has been reset on the current split */
   gboolean rate_reset;
 
+  /* account on the current split when the exchange rate was last set */
+  Account *rate_account;
+
   /* User data for users of SplitRegisters */
   gpointer user_data;
 



More information about the gnucash-changes mailing list