[Gnucash-changes] r14247 - gnucash/branches/register-rewrite/src - Two changes to gnc_xfer_dialog_run_exchange_dialog().

Chris Shoemaker chris at cvs.gnucash.org
Mon May 29 16:55:37 EDT 2006


Author: chris
Date: 2006-05-29 16:55:36 -0400 (Mon, 29 May 2006)
New Revision: 14247
Trac: http://svn.gnucash.org/trac/changeset/14247

Modified:
   gnucash/branches/register-rewrite/src/gnome-utils/dialog-transfer.c
   gnucash/branches/register-rewrite/src/gnome-utils/dialog-transfer.h
   gnucash/branches/register-rewrite/src/register/ledger-core/split-register-control.c
Log:
  Two changes to gnc_xfer_dialog_run_exchange_dialog().
  - pass the converted amount back to the caller
  - pass in the commodity directly, instead getting the commodity from an 
    account.


Modified: gnucash/branches/register-rewrite/src/gnome-utils/dialog-transfer.c
===================================================================
--- gnucash/branches/register-rewrite/src/gnome-utils/dialog-transfer.c	2006-05-29 20:48:58 UTC (rev 14246)
+++ gnucash/branches/register-rewrite/src/gnome-utils/dialog-transfer.c	2006-05-29 20:55:36 UTC (rev 14247)
@@ -1986,7 +1986,8 @@
     GtkWidget *box    = gnc_glade_lookup_widget (xferData->dialog,
                                                  "transfermain-vbox" );
     gtk_box_pack_end( GTK_BOX(box), button, FALSE, FALSE, 0 );
-    g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (callback), user_data);
+    g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (callback),
+                      user_data);
     gtk_widget_show( button );
   }
 }
@@ -2157,12 +2158,12 @@
 
 
 gboolean gnc_xfer_dialog_run_exchange_dialog(
-    XferDialog *xfer, gnc_numeric *exch_rate, gnc_numeric amount, 
-    Account *reg_acc, Transaction *txn, gnc_commodity *xfer_com)
+    XferDialog *xfer, gnc_numeric *exch_rate, gnc_numeric *amount,
+    gnc_commodity *reg_com, Transaction *txn,
+    gnc_commodity *xfer_com)
 {
     gboolean swap_amounts = FALSE;
     gnc_commodity *txn_cur = xaccTransGetCurrency(txn);
-    gnc_commodity *reg_com = xaccAccountGetCommodity(reg_acc);
 
     /* We know that "amount" is always in the reg_com currency.
      * Unfortunately it is possible that neither xfer_com or txn_cur are
@@ -2187,11 +2188,13 @@
         /* UGGH -- we're not in either.  That means we need to convert
          * 'amount' from the register commodity to the txn currency.
          */
-        gnc_numeric rate = xaccTransGetAccountConvRate(txn, reg_acc);
-        
+        gnc_numeric rate;
+        if (!xaccTransGetRateForCommodity(txn, reg_com, NULL, &rate))
+            return TRUE;
+
         /* XXX: should we tell the user we've done the conversion? */
-        amount = gnc_numeric_div(
-            amount, rate, 
+        *amount = gnc_numeric_div(
+            *amount, rate,
             gnc_commodity_get_fraction(txn_cur), GNC_DENOM_REDUCE);
     }
     
@@ -2209,7 +2212,7 @@
     gnc_xfer_dialog_hide_to_account_tree(xfer);
     gnc_xfer_dialog_hide_from_account_tree(xfer);
     
-    gnc_xfer_dialog_set_amount(xfer, amount);
+    gnc_xfer_dialog_set_amount(xfer, *amount);
     
     /*
      * When we flip, we should tell the dialog so it can deal with the
@@ -2226,8 +2229,12 @@
     /* If we swapped the amounts for the dialog, then make sure we swap
      * it back now...
      */
-    if (swap_amounts)
+    if (swap_amounts) {
+        *amount = gnc_numeric_mul(*amount, *exch_rate,
+                                  gnc_commodity_get_fraction(txn_cur),
+                                  GNC_DENOM_REDUCE);
         *exch_rate = gnc_numeric_div(gnc_numeric_create(1, 1), *exch_rate,
                                      GNC_DENOM_AUTO, GNC_DENOM_REDUCE);
+    }
     return FALSE;
 }

Modified: gnucash/branches/register-rewrite/src/gnome-utils/dialog-transfer.h
===================================================================
--- gnucash/branches/register-rewrite/src/gnome-utils/dialog-transfer.h	2006-05-29 20:48:58 UTC (rev 14246)
+++ gnucash/branches/register-rewrite/src/gnome-utils/dialog-transfer.h	2006-05-29 20:55:36 UTC (rev 14247)
@@ -199,18 +199,44 @@
 				gpointer user_data);
 
 /* Uses the XferDialog to obtain from the user an explicit exchange
-   rate.  This exchange rate will then be uses to converting 'amount',
-   which is given in the commodity of the register Account, reg_acc,
-   into a split value for a split whose Account is the commodity
-   specified by xfer_com.
+   rate.
 
-   The 'exch_rate' argument is used to set the initial value of the
-   rate.  If the dialog completes sucessfully 'FALSE' is returned and
-   'exch_rate' is also used to store the converted value.  Otherwise,
-   TRUE is returned and the 'exch_rate' argument is undefined.
+   @param xfer Dialog data structure
+
+   @param exch_rate A pointer to the rate used to set the initial
+   value of the rate; also used to return the rate from the
+   transaction currency to the split commodity.
+
+   @param amount A pointer to the amount used to initialize the
+   dialog; also used to return the value of 'amount' in the 'xfer_com'
+
+   @param reg_com The commodity in which 'amount' in in, when passed
+   to this function.
+
+   @param txn The transaction whose currency will be used in the transfer
+
+   @param xfer_com The commodirt in which 'amount' is in, when returned
+   from this function.
+
+   Notes: The final exchange rate will be used to convert 'amount',
+   which is given in the commodity, 'reg_com', into a split amount for
+   a split whose Account is the commodity specified by xfer_com.
+
+   If the dialog completes sucessfully, 'FALSE' is returned and
+   'exch_rate' is also used to store the updated rate and 'amount'
+   is used to store the corresponding amount in the 'xfer_com'
+   commodity.  Otherwise, TRUE is returned and the 'exch_rate' and
+   'amount' arguments are undefined.
+
+   Note that 'exch_rate' isn't necessarily the rate from reg_com into
+   xfer_com.  If the transaction currency is different from reg_com
+   then it will be the rate from the transaction currency into
+   xfer_com, instead.
+
 */
 gboolean gnc_xfer_dialog_run_exchange_dialog(
-    XferDialog *xfer, gnc_numeric *exch_rate, gnc_numeric amount, 
-    Account *reg_acc, Transaction *txn, gnc_commodity *xfer_com);
+    XferDialog *xfer, gnc_numeric *exch_rate, gnc_numeric *amount,
+    gnc_commodity *reg_com, Transaction *txn,
+    gnc_commodity *xfer_com);
 
 #endif

Modified: gnucash/branches/register-rewrite/src/register/ledger-core/split-register-control.c
===================================================================
--- gnucash/branches/register-rewrite/src/register/ledger-core/split-register-control.c	2006-05-29 20:48:58 UTC (rev 14246)
+++ gnucash/branches/register-rewrite/src/register/ledger-core/split-register-control.c	2006-05-29 20:55:36 UTC (rev 14247)
@@ -1138,7 +1138,7 @@
           gnc_split_register_get_cell_date(reg, DATE_CELL)));
 
   if (gnc_xfer_dialog_run_exchange_dialog(
-          xfer, &exch_rate, amount, reg_acc, txn, xfer_com))
+          xfer, &exch_rate, &amount, reg_com, txn, xfer_com))
       return TRUE;
 
   /* Set the RATE_CELL on this cursor and mark it changed */



More information about the gnucash-changes mailing list