r17519 - gnucash/branches/2.2/src/gnome-utils - [r17451, r17462] Bug #543780, #547335: Scrub the transfer dialog calculation of the "to" amount:
Andreas Köhler
andi5 at cvs.gnucash.org
Sun Sep 14 17:30:46 EDT 2008
Author: andi5
Date: 2008-09-14 17:30:46 -0400 (Sun, 14 Sep 2008)
New Revision: 17519
Trac: http://svn.gnucash.org/trac/changeset/17519
Modified:
gnucash/branches/2.2/src/gnome-utils/dialog-transfer.c
Log:
[r17451,r17462] Bug #543780, #547335: Scrub the transfer dialog calculation of the "to" amount:
-Check account value to avoid causing a CRIT message.
-Reorganize function for smaller size and more readability.
-Add some comments (there were none).
Committed by cedayiv.
Modified: gnucash/branches/2.2/src/gnome-utils/dialog-transfer.c
===================================================================
--- gnucash/branches/2.2/src/gnome-utils/dialog-transfer.c 2008-09-14 21:30:37 UTC (rev 17518)
+++ gnucash/branches/2.2/src/gnome-utils/dialog-transfer.c 2008-09-14 21:30:46 UTC (rev 17519)
@@ -825,48 +825,42 @@
static void
gnc_xfer_update_to_amount (XferDialog *xferData)
{
- gnc_numeric amount, price, to_amount;
+ GNCAmountEdit *amount_edit, *price_edit, *to_amount_edit;
+ gnc_numeric price, to_amount;
Account *account;
+ int scu = 0;
- 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);
+ g_return_if_fail(xferData);
+ /* Get the amount editing controls of the dialog. */
+ amount_edit = GNC_AMOUNT_EDIT(xferData->amount_edit);
+ 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)
- {
- GtkEntry *entry;
+ 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);
- gnc_amount_edit_set_amount(GNC_AMOUNT_EDIT(xferData->to_amount_edit),
- gnc_numeric_zero ());
- entry = GTK_ENTRY(gnc_amount_edit_gtk_entry
- (GNC_AMOUNT_EDIT(xferData->to_amount_edit)));
- gtk_entry_set_text(entry, "");
- }
-
- gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (xferData->price_edit));
-
- amount = gnc_amount_edit_get_amount(GNC_AMOUNT_EDIT(xferData->amount_edit));
- price = gnc_amount_edit_get_amount(GNC_AMOUNT_EDIT(xferData->price_edit));
-
- if (gnc_numeric_zero_p (price))
- to_amount = gnc_numeric_zero ();
+ /* Determine the amount to transfer. */
+ 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 (amount, price,
- xaccAccountGetCommoditySCU (account),
- GNC_RND_ROUND);
+ to_amount = gnc_numeric_mul(gnc_amount_edit_get_amount(amount_edit),
+ price, scu, GNC_RND_ROUND);
- gnc_amount_edit_set_amount(GNC_AMOUNT_EDIT(xferData->to_amount_edit),
- to_amount);
+ /* Update the dialog. */
+ gnc_amount_edit_set_amount(to_amount_edit, to_amount);
+ if (gnc_numeric_zero_p(to_amount))
+ gtk_entry_set_text(GTK_ENTRY(gnc_amount_edit_gtk_entry(to_amount_edit)),
+ "");
- if (gnc_numeric_zero_p (to_amount))
- {
- GtkEntry *entry;
-
- entry = GTK_ENTRY(gnc_amount_edit_gtk_entry
- (GNC_AMOUNT_EDIT(xferData->to_amount_edit)));
- gtk_entry_set_text(entry, "");
- }
-
gnc_xfer_dialog_update_conv_info(xferData);
}
More information about the gnucash-changes
mailing list