mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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 git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21713 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
89eaf45a7d
commit
4adf872d74
@ -765,13 +765,15 @@ gnc_invoice_window_postCB (GtkWidget *unused_widget, gpointer data)
|
||||
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 @@ gnc_invoice_window_postCB (GtkWidget *unused_widget, gpointer data)
|
||||
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 @@ gnc_invoice_window_postCB (GtkWidget *unused_widget, gpointer data)
|
||||
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;
|
||||
|
@ -1381,7 +1381,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
||||
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 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user