Skip to content

Commit

Permalink
Fix a bug in r22646: incorrect test for equivalent price already in p…
Browse files Browse the repository at this point in the history
…rice DB

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22660 57a11ea4-9604-0410-9ed3-97b8803252fd
  • Loading branch information
mtalexander committed Dec 17, 2012
1 parent 4af0355 commit 0604921
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/gnome-utils/dialog-transfer.c
Expand Up @@ -1544,28 +1544,29 @@ gnc_xfer_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
GNCPrice *price;
gnc_numeric value;
gnc_commodity *tmp;
gnc_numeric from_amt, to_amt;
gnc_numeric tmp_amt;

from_amt = gnc_amount_edit_get_amount(GNC_AMOUNT_EDIT(xferData->amount_edit));
to_amt = gnc_amount_edit_get_amount(GNC_AMOUNT_EDIT(xferData->to_amount_edit));

/* compute the price -- maybe we need to swap? */

value = gnc_xfer_dialog_compute_price(xferData);
value = gnc_numeric_div(to_amt, from_amt, GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);
value = gnc_numeric_abs (value);

/* Try to be consistent about how quotes are installed. */
if (from == gnc_default_currency())
{
tmp = from;
from = to;
to = tmp;
value = gnc_numeric_div (gnc_numeric_create(1, 1), value,
GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);
}
else if ((to != gnc_default_currency()) &&
if (from == gnc_default_currency() ||
((to != gnc_default_currency()) &&
(strcmp (gnc_commodity_get_mnemonic(from),
gnc_commodity_get_mnemonic(to)) < 0))
gnc_commodity_get_mnemonic(to)) < 0)))
{
tmp = from;
from = to;
to = tmp;
tmp_amt = from_amt;
from_amt = to_amt;
to_amt = tmp_amt;
value = gnc_numeric_div (gnc_numeric_create(1, 1), value,
GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);
}
Expand All @@ -1575,10 +1576,9 @@ gnc_xfer_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
if (price)
{
gnc_numeric price_value = gnc_price_get_value(price);
if (!gnc_numeric_same (value, price_value,
MIN(gnc_numeric_denom(value),
gnc_numeric_denom(price_value)),
GNC_HOW_RND_ROUND_HALF_UP))
if (!gnc_numeric_equal (gnc_numeric_mul (from_amt, price_value,
GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE),
to_amt))
{
gnc_price_unref (price);
price = NULL;
Expand All @@ -1595,10 +1595,9 @@ gnc_xfer_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
gnc_numeric price_value = gnc_numeric_div (gnc_numeric_create(1, 1),
gnc_price_get_value(price),
GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);
if (!gnc_numeric_same (value, price_value,
MIN(gnc_numeric_denom(value),
gnc_numeric_denom(price_value)),
GNC_HOW_RND_ROUND_HALF_UP))
if (!gnc_numeric_equal (gnc_numeric_mul (from_amt, price_value,
GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE),
to_amt))
{
gnc_price_unref (price);
price = NULL;
Expand Down

0 comments on commit 0604921

Please sign in to comment.