From ec8ed38860e9ec79889a28bc499a31dc6caca0da Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Sat, 13 Jun 2015 17:43:54 +0200 Subject: [PATCH] Bug 746792 - process payment in foreign currency leads to broken equation The payment dialog was inconsistent in interpreting amounts and values. By clicking on documents the document's amount is added to the Payment field suggesting it's in the owner's currency. However the post-processing code took that amount as being the amount in the transfer accounts currency and calculated the rest backwards. This will now become: the amount fields are interpreted in the owner's currency and the exchange rate asked will be from owner's currenty to transfer account's currency. --- src/business/business-gnome/dialog-payment.c | 4 ++-- src/engine/gncOwner.c | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/business/business-gnome/dialog-payment.c b/src/business/business-gnome/dialog-payment.c index 298cb6981f..e8e2dd025b 100644 --- a/src/business/business-gnome/dialog-payment.c +++ b/src/business/business-gnome/dialog-payment.c @@ -691,10 +691,10 @@ gnc_payment_ok_cb (GtkWidget *widget, gpointer data) text = _("The transfer and post accounts are associated with different currencies. Please specify the conversion rate."); - xfer = gnc_xfer_dialog(pw->dialog, pw->xfer_acct); + xfer = gnc_xfer_dialog(pw->dialog, pw->post_acct); gnc_info_dialog(pw->dialog, "%s", text); - gnc_xfer_dialog_select_to_account(xfer, pw->post_acct); + gnc_xfer_dialog_select_to_account(xfer, pw->xfer_acct); gnc_xfer_dialog_set_amount(xfer, pw->amount_tot); /* All we want is the exchange rate so prevent the user from thinking diff --git a/src/engine/gncOwner.c b/src/engine/gncOwner.c index 25fa682438..b0e7ecaef1 100644 --- a/src/engine/gncOwner.c +++ b/src/engine/gncOwner.c @@ -809,12 +809,17 @@ gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction *txn, } else { - /* Need to value the payment in terms of the owner commodity */ - gnc_numeric payment_value = gnc_numeric_mul(amount, - exch, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND_HALF_UP); + /* This will be a multi-currency transaction. The amount passed to this + * function is in the owner commodity (also used by the post account). + * For the xfer split we also need to value the payment in the xfer account's + * commodity. + * exch is from post account to xfer account so that can be used directly + * to calculate the equivalent amount in the xfer account's commodity. */ + gnc_numeric xfer_amount = gnc_numeric_mul (amount, exch, GNC_DENOM_AUTO, + GNC_HOW_RND_ROUND_HALF_UP); - xaccSplitSetAmount(split, amount); - xaccSplitSetValue(split, payment_value); + xaccSplitSetAmount(split, xfer_amount); /* Payment in xfer account currency */ + xaccSplitSetValue(split, amount); /* Payment in transaction currency */ } }