From d89d96ce880856c067f7442385f32aef4c412bb2 Mon Sep 17 00:00:00 2001 From: Charles Day Date: Mon, 11 Aug 2008 21:55:50 +0000 Subject: [PATCH] Bug #547335: Get the exchange rate dialog "to" amount working again when launched via the register instead of the menu. BP git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17462 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/gnome-utils/dialog-transfer.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/gnome-utils/dialog-transfer.c b/src/gnome-utils/dialog-transfer.c index af4ba0737d..906b73d144 100644 --- a/src/gnome-utils/dialog-transfer.c +++ b/src/gnome-utils/dialog-transfer.c @@ -834,6 +834,7 @@ gnc_xfer_update_to_amount (XferDialog *xferData) GNCAmountEdit *amount_edit, *price_edit, *to_amount_edit; gnc_numeric price, to_amount; Account *account; + int scu = 0; g_return_if_fail(xferData); @@ -842,21 +843,23 @@ gnc_xfer_update_to_amount (XferDialog *xferData) price_edit = GNC_AMOUNT_EDIT(xferData->price_edit); to_amount_edit = GNC_AMOUNT_EDIT(xferData->to_amount_edit); + /* Determine the SCU (smallest commodity unit) of the "to" amount. */ account = gnc_transfer_dialog_get_selected_account(xferData, XFER_DIALOG_TO); if (account == NULL) account = gnc_transfer_dialog_get_selected_account(xferData, XFER_DIALOG_FROM); + if (account != NULL) + scu = xaccAccountGetCommoditySCU(account); + else if (xferData->to_commodity != NULL) + scu = gnc_commodity_get_fraction(xferData->to_commodity); /* Determine the amount to transfer. */ - if (account == NULL || - !gnc_amount_edit_evaluate(price_edit) || + if (!gnc_amount_edit_evaluate(price_edit) || gnc_numeric_zero_p(price = gnc_amount_edit_get_amount(price_edit))) to_amount = gnc_numeric_zero(); else to_amount = gnc_numeric_mul(gnc_amount_edit_get_amount(amount_edit), - price, - xaccAccountGetCommoditySCU(account), - GNC_RND_ROUND); + price, scu, GNC_RND_ROUND); /* Update the dialog. */ gnc_amount_edit_set_amount(to_amount_edit, to_amount);