AUDIT: r21713 - gnucash/trunk/src - Bug #649362 - Transfer Funds Window Exchange Rate and Decimal Points
Geert Janssens
gjanssens at code.gnucash.org
Sun Dec 11 12:53:52 EST 2011
Author: gjanssens
Date: 2011-12-11 12:53:52 -0500 (Sun, 11 Dec 2011)
New Revision: 21713
Trac: http://svn.gnucash.org/trac/changeset/21713
Modified:
gnucash/trunk/src/business/business-gnome/dialog-invoice.c
gnucash/trunk/src/engine/gncInvoice.c
Log:
Bug #649362 - Transfer Funds Window Exchange Rate and Decimal Points
Rounding in Bill/Invoices
This patch fixes the rounding by showing the actual value to convert. As
a result the exchange rate direction had to be swapped as well to avoid
lots of confusion.
BP
Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c 2011-12-11 17:53:42 UTC (rev 21712)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c 2011-12-11 17:53:52 UTC (rev 21713)
@@ -765,13 +765,15 @@
for (entries_iter = entries; entries_iter != NULL; entries_iter = g_list_next(entries_iter))
{
Account *this_acc;
+ gnc_commodity *account_currency;
entry = (GncEntry*)entries_iter->data;
this_acc = (reverse ? gncEntryGetInvAccount (entry) :
gncEntryGetBillAccount (entry));
+ account_currency = xaccAccountGetCommodity (this_acc);
if (this_acc &&
- !gnc_commodity_equal (gncInvoiceGetCurrency (invoice), xaccAccountGetCommodity (this_acc)))
+ !gnc_commodity_equal (gncInvoiceGetCurrency (invoice), account_currency))
{
GNCPrice *convprice;
@@ -781,18 +783,37 @@
show_dialog = FALSE;
}
- convprice = gncInvoiceGetPrice(invoice, xaccAccountGetCommodity(this_acc));
+ convprice = gncInvoiceGetPrice(invoice, account_currency);
if (convprice == NULL)
{
XferDialog *xfer;
gnc_numeric exch_rate;
Timespec date;
gnc_numeric amount = gnc_numeric_create(1, 1);
+ gnc_numeric value;
+ gnc_numeric tax;
+ /* Note some twisted logic here:
+ * We ask the exchange rate
+ * FROM invoice currency
+ * TO other account currency
+ * Because that's what happens logically.
+ * But the internal posting logic works backwards:
+ * It searches for an exchange rate
+ * FROM other account currency
+ * TO invoice currency
+ * So we will store the inverted exchange rate
+ */
+ /* Obtain the Entry's total value (net + tax) */
+ gncEntryGetValue (entry, is_cust_doc, &value, NULL, &tax, NULL);
+ amount = gnc_numeric_add (value, tax,
+ gnc_commodity_get_fraction (account_currency),
+ GNC_HOW_RND_ROUND_HALF_UP );
+
/* create the exchange-rate dialog */
- xfer = gnc_xfer_dialog (iw_get_window(iw), this_acc);
- gnc_xfer_dialog_select_to_account(xfer, acc);
+ xfer = gnc_xfer_dialog (iw_get_window(iw), acc);
+ gnc_xfer_dialog_select_to_account(xfer, this_acc);
gnc_xfer_dialog_set_amount(xfer, amount);
/* All we want is the exchange rate so prevent the user from thinking
@@ -805,9 +826,14 @@
if (gnc_xfer_dialog_run_until_done(xfer))
{
/* User finished the transfer dialog successfully */
+
+ /* Invert the exchange rate as explained above */
+ if (!gnc_numeric_zero_p (exch_rate))
+ exch_rate = gnc_numeric_div ((gnc_numeric) {1, 1}, exch_rate,
+ GNC_DENOM_AUTO, GNC_HOW_RND_ROUND_HALF_UP);
convprice = gnc_price_create(iw->book);
gnc_price_begin_edit (convprice);
- gnc_price_set_commodity (convprice, xaccAccountGetCommodity(this_acc));
+ gnc_price_set_commodity (convprice, account_currency);
gnc_price_set_currency (convprice, gncInvoiceGetCurrency (invoice));
date.tv_sec = time (NULL);
date.tv_nsec = 0;
Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c 2011-12-11 17:53:42 UTC (rev 21712)
+++ gnucash/trunk/src/engine/gncInvoice.c 2011-12-11 17:53:52 UTC (rev 21713)
@@ -1381,7 +1381,7 @@
gnc_numeric converted_amount;
xaccSplitSetValue(split, (is_cust_doc ? gnc_numeric_neg(value) : value));
converted_amount = gnc_numeric_div(value, gnc_price_get_value(price), GNC_DENOM_AUTO, GNC_HOW_RND_ROUND_HALF_UP);
- printf("converting from %f to %f\n", gnc_numeric_to_double(value), gnc_numeric_to_double(converted_amount));
+ DEBUG("converting from %f to %f\n", gnc_numeric_to_double(value), gnc_numeric_to_double(converted_amount));
xaccSplitSetAmount(split, is_cust_doc ? gnc_numeric_neg(converted_amount) : converted_amount);
}
}
@@ -1472,7 +1472,7 @@
gnc_numeric converted_amount;
xaccSplitSetValue(split, (is_cust_doc ? gnc_numeric_neg(acc_val->value) : acc_val->value));
converted_amount = gnc_numeric_div(acc_val->value, gnc_price_get_value(price), GNC_DENOM_AUTO, GNC_HOW_RND_ROUND_HALF_UP);
- printf("converting from %f to %f\n", gnc_numeric_to_double(acc_val->value), gnc_numeric_to_double(converted_amount));
+ DEBUG("converting from %f to %f\n", gnc_numeric_to_double(acc_val->value), gnc_numeric_to_double(converted_amount));
xaccSplitSetAmount(split, is_cust_doc ? gnc_numeric_neg(converted_amount) : converted_amount);
}
More information about the gnucash-changes
mailing list