[Gnucash-changes] r13426 - gnucash/trunk/src/register/ledger-core - Make register use engine-provided xaccTransGetAccountConvRate() instead of

Chris Shoemaker chris at cvs.gnucash.org
Tue Feb 28 14:57:25 EST 2006


Author: chris
Date: 2006-02-28 14:57:24 -0500 (Tue, 28 Feb 2006)
New Revision: 13426
Trac: http://svn.gnucash.org/trac/changeset/13426

Modified:
   gnucash/trunk/src/register/ledger-core/split-register-control.c
   gnucash/trunk/src/register/ledger-core/split-register-model-save.c
   gnucash/trunk/src/register/ledger-core/split-register-model.c
   gnucash/trunk/src/register/ledger-core/split-register-p.h
Log:
   Make register use engine-provided xaccTransGetAccountConvRate() instead of
   writing its own.


Modified: gnucash/trunk/src/register/ledger-core/split-register-control.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-control.c	2006-02-28 19:46:19 UTC (rev 13425)
+++ gnucash/trunk/src/register/ledger-core/split-register-control.c	2006-02-28 19:57:24 UTC (rev 13426)
@@ -1154,7 +1154,7 @@
     /* UGGH -- we're not in either.  That means we need to convert 'amount'
      * from the register commodity to the txn currency.
      */
-    gnc_numeric rate = gnc_split_register_get_conv_rate (txn, reg_acc);
+    gnc_numeric rate = xaccTransGetAccountConvRate(txn, reg_acc);
 
     /* XXX: should we tell the user we've done the conversion? */
     amount = gnc_numeric_div (amount, rate, gnc_commodity_get_fraction (txn_cur),

Modified: gnucash/trunk/src/register/ledger-core/split-register-model-save.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-model-save.c	2006-02-28 19:46:19 UTC (rev 13425)
+++ gnucash/trunk/src/register/ledger-core/split-register-model-save.c	2006-02-28 19:57:24 UTC (rev 13426)
@@ -419,7 +419,7 @@
      * Otherwise, we _can_ use the rate_cell!
      */
     if (sd->reg_expanded && ! gnc_commodity_equal (reg_com, xfer_com))
-      amtconv = gnc_split_register_get_conv_rate (sd->trans, acc);
+      amtconv = xaccTransGetAccountConvRate(sd->trans, acc);
     else
       amtconv = convrate;
 
@@ -534,8 +534,8 @@
        * _both_ accounts -- so grab the other exchange rate.
        */
       if (gnc_numeric_zero_p (rate) || split_needs_amount)
-	rate = gnc_split_register_get_conv_rate (xaccSplitGetParent (other_split),
-						 acc);
+          rate = xaccTransGetAccountConvRate(xaccSplitGetParent (other_split),
+                                             acc);
 
       amount = gnc_numeric_mul (value, rate, xaccAccountGetCommoditySCU (acc),
 				GNC_RND_ROUND);

Modified: gnucash/trunk/src/register/ledger-core/split-register-model.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-model.c	2006-02-28 19:46:19 UTC (rev 13425)
+++ gnucash/trunk/src/register/ledger-core/split-register-model.c	2006-02-28 19:57:24 UTC (rev 13426)
@@ -1413,56 +1413,6 @@
   return TRUE;
 }
 
-/* Compute the conversion rate for the transaction to this account.
- * Any "split value" (which is in the transaction currency),
- * multiplied by this conversion rate, will give you the value you
- * should display for this account.
- */
-gnc_numeric
-gnc_split_register_get_conv_rate (Transaction *txn, Account *acc)
-{
-  gnc_numeric amount, value, convrate;
-  GList *splits;
-  Split *s;
-  gboolean found_acc_match = FALSE;
-
-  /* We need to compute the conversion rate into _this account_.  So,
-   * find the first split into this account, compute the conversion
-   * rate (based on amount/value), and then return this conversion
-   * rate.
-   */
-  splits = xaccTransGetSplitList(txn);
-  for (; splits; splits = splits->next) {
-    s = splits->data;
-    
-    if (xaccSplitGetAccount (s) != acc)
-      continue;
-
-    found_acc_match = TRUE;
-    amount = xaccSplitGetAmount (s);
-
-    /* Ignore splits with "zero" amount */
-    if (gnc_numeric_zero_p (amount))
-      continue;
-
-    value = xaccSplitGetValue (s);
-    convrate = gnc_numeric_div (amount, value, GNC_DENOM_AUTO, GNC_DENOM_REDUCE);
-    return convrate;
-  }
-
-  /* Don't error if we're in a GENERAL_LEDGER and have no account */
-  if (acc) {
-    /* If we did find a matching account but it's amount was zero,
-     * then perhaps this is a "special" income/loss transaction
-     */
-    if (found_acc_match)
-      return gnc_numeric_zero();
-    else
-      PERR ("Cannot convert transaction -- no splits with proper conversion ratio");
-  }
-  return gnc_numeric_create (100, 100);
-}
-
 /* Convert the amount/value of the Split for viewing in the account --
  * in particular we want to convert the Split to be in to_commodity.
  * Returns the amount.
@@ -1508,7 +1458,7 @@
    * compute the conversion rate (based on amount/value), and then multiply
    * this times the split value.
    */
-  convrate = gnc_split_register_get_conv_rate (txn, account);
+  convrate = xaccTransGetAccountConvRate(txn, account);
   value = xaccSplitGetValue (split);
   return gnc_numeric_mul (value, convrate,
 			  gnc_commodity_get_fraction (to_commodity),
@@ -1563,7 +1513,7 @@
     acc = gnc_split_register_get_default_account (reg);
     if (gnc_split_register_needs_conv_rate (reg, trans, acc)) {
       imbalance = gnc_numeric_mul (imbalance,
-				   gnc_split_register_get_conv_rate (trans, acc),
+				   xaccTransGetAccountConvRate(trans, acc),
 				   gnc_commodity_get_fraction (currency),
 				   GNC_RND_ROUND);
     } else {

Modified: gnucash/trunk/src/register/ledger-core/split-register-p.h
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-p.h	2006-02-28 19:46:19 UTC (rev 13425)
+++ gnucash/trunk/src/register/ledger-core/split-register-p.h	2006-02-28 19:57:24 UTC (rev 13426)
@@ -166,6 +166,5 @@
 gboolean gnc_split_reg_has_rate_cell (SplitRegisterType type);
 gboolean gnc_split_register_split_needs_amount (SplitRegister *reg, Split *split);
 gboolean gnc_split_register_needs_conv_rate (SplitRegister *reg, Transaction *txn, Account *acc);
-gnc_numeric gnc_split_register_get_conv_rate (Transaction *txn, Account *acc);
 
 #endif



More information about the gnucash-changes mailing list