r17863 - gnucash/branches/2.2/src/engine - [17850] Bug #568945: gnc_pricedb_convert_balance_* should look for the reciprocal of the exchange rate
Christian Stimming
cstim at cvs.gnucash.org
Sat Jan 31 05:46:12 EST 2009
Author: cstim
Date: 2009-01-31 05:46:12 -0500 (Sat, 31 Jan 2009)
New Revision: 17863
Trac: http://svn.gnucash.org/trac/changeset/17863
Modified:
gnucash/branches/2.2/src/engine/gnc-pricedb.c
Log:
[17850] Bug #568945: gnc_pricedb_convert_balance_* should look for the reciprocal of the exchange rate
If the price DB contains the reciprocal of the exchange rate which
gnc_pricedb_convert_balance_nearest_price,
gnc_pricedb_convert_balance_latest_price, and
gnc_pricedb_convert_balance_latest_before need to do their conversion they
don't find it and return zero.
Patch by Mike Alexander.
Modified: gnucash/branches/2.2/src/engine/gnc-pricedb.c
===================================================================
--- gnucash/branches/2.2/src/engine/gnc-pricedb.c 2009-01-31 10:46:03 UTC (rev 17862)
+++ gnucash/branches/2.2/src/engine/gnc-pricedb.c 2009-01-31 10:46:12 UTC (rev 17863)
@@ -1847,6 +1847,18 @@
return balance;
}
+ /* Look for a price of the new currency in the balance currency and use
+ * the reciprocal if we find it
+ */
+ price = gnc_pricedb_lookup_latest (pdb, new_currency, balance_currency);
+ if (price) {
+ balance = gnc_numeric_div (balance, gnc_price_get_value (price),
+ gnc_commodity_get_fraction (new_currency),
+ GNC_HOW_RND_ROUND);
+ gnc_price_unref (price);
+ return balance;
+ }
+
/*
* no direct price found, try if we find a price in another currency
* and convert in two stages
@@ -1884,7 +1896,7 @@
list_helper = list_helper->next;
} while((list_helper != NULL) &&
- (!gnc_numeric_zero_p(currency_price_value)));
+ (gnc_numeric_zero_p(currency_price_value)));
balance = gnc_numeric_mul (balance, currency_price_value,
GNC_DENOM_AUTO,
@@ -1923,6 +1935,18 @@
return balance;
}
+ /* Look for a price of the new currency in the balance currency and use
+ * the reciprocal if we find it
+ */
+ price = gnc_pricedb_lookup_nearest_in_time (pdb, new_currency, balance_currency, t);
+ if (price) {
+ balance = gnc_numeric_div (balance, gnc_price_get_value (price),
+ gnc_commodity_get_fraction (new_currency),
+ GNC_HOW_RND_ROUND);
+ gnc_price_unref (price);
+ return balance;
+ }
+
/*
* no direct price found, try if we find a price in another currency
* and convert in two stages
@@ -1960,7 +1984,7 @@
list_helper = list_helper->next;
} while((list_helper != NULL) &&
- (!gnc_numeric_zero_p(currency_price_value)));
+ (gnc_numeric_zero_p(currency_price_value)));
balance = gnc_numeric_mul (balance, currency_price_value,
gnc_commodity_get_fraction (new_currency),
@@ -2002,6 +2026,18 @@
return balance;
}
+ /* Look for a price of the new currency in the balance currency and use
+ * the reciprocal if we find it.
+ */
+ price = gnc_pricedb_lookup_latest_before (pdb, new_currency, balance_currency, t);
+ if (price) {
+ balance = gnc_numeric_div (balance, gnc_price_get_value (price),
+ gnc_commodity_get_fraction (new_currency),
+ GNC_HOW_RND_ROUND);
+ gnc_price_unref (price);
+ return balance;
+ }
+
/*
* no direct price found, try if we find a price in another currency
* and convert in two stages
@@ -2039,7 +2075,7 @@
list_helper = list_helper->next;
} while((list_helper != NULL) &&
- (!gnc_numeric_zero_p(currency_price_value)));
+ (gnc_numeric_zero_p(currency_price_value)));
balance = gnc_numeric_mul (balance, currency_price_value,
gnc_commodity_get_fraction (new_currency),
More information about the gnucash-changes
mailing list