mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Adjust split_register to match transfer dialog checking inverted prices.
This commit is contained in:
parent
348fe45b76
commit
76c1259f1b
@ -2056,6 +2056,7 @@ record_price (SplitRegister *reg, Account *account, gnc_numeric value)
|
|||||||
int scu = gnc_commodity_get_fraction(curr);
|
int scu = gnc_commodity_get_fraction(curr);
|
||||||
Timespec ts;
|
Timespec ts;
|
||||||
BasicCell *cell = gnc_table_layout_get_cell (reg->table->layout, DATE_CELL);
|
BasicCell *cell = gnc_table_layout_get_cell (reg->table->layout, DATE_CELL);
|
||||||
|
gboolean swap = FALSE;
|
||||||
|
|
||||||
/* Only record the price for account types that don't have a
|
/* Only record the price for account types that don't have a
|
||||||
* "rate" cell. They'll get handled later by
|
* "rate" cell. They'll get handled later by
|
||||||
@ -2065,24 +2066,20 @@ record_price (SplitRegister *reg, Account *account, gnc_numeric value)
|
|||||||
return;
|
return;
|
||||||
gnc_date_cell_get_date ((DateCell*)cell, &ts);
|
gnc_date_cell_get_date ((DateCell*)cell, &ts);
|
||||||
price = gnc_pricedb_lookup_day (pricedb, comm, curr, ts);
|
price = gnc_pricedb_lookup_day (pricedb, comm, curr, ts);
|
||||||
if (price)
|
if (!price)
|
||||||
{
|
|
||||||
price_value = gnc_price_get_value(price);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
price = gnc_pricedb_lookup_day (pricedb, curr, comm, ts);
|
price = gnc_pricedb_lookup_day (pricedb, curr, comm, ts);
|
||||||
if (price)
|
if (price)
|
||||||
{
|
|
||||||
/* It might be better to raise an error here: We shouldn't be creating
|
/* It might be better to raise an error here: We shouldn't be creating
|
||||||
* currency->commodity prices.
|
* currency->commodity prices.
|
||||||
*/
|
*/
|
||||||
price_value = gnc_numeric_invert(gnc_price_get_value(price));
|
swap = TRUE;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (price)
|
if (price)
|
||||||
{
|
{
|
||||||
if (gnc_numeric_equal(value, price_value))
|
price_value = gnc_price_get_value(price);
|
||||||
|
if (gnc_numeric_equal(swap ? gnc_numeric_invert(value) : value,
|
||||||
|
price_value))
|
||||||
{
|
{
|
||||||
gnc_price_unref (price);
|
gnc_price_unref (price);
|
||||||
return;
|
return;
|
||||||
@ -2092,16 +2089,13 @@ record_price (SplitRegister *reg, Account *account, gnc_numeric value)
|
|||||||
gnc_price_unref(price);
|
gnc_price_unref(price);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!gnc_numeric_eq(price_value, gnc_price_get_value(price)))
|
if (swap)
|
||||||
{
|
{
|
||||||
value = gnc_numeric_invert(value);
|
value = gnc_numeric_invert(value);
|
||||||
scu = gnc_commodity_get_fraction(comm);
|
scu = gnc_commodity_get_fraction(comm);
|
||||||
value = gnc_numeric_convert(value, scu * COMMODITY_DENOM_MULT,
|
|
||||||
GNC_HOW_RND_ROUND_HALF_UP);
|
|
||||||
}
|
}
|
||||||
else
|
value = gnc_numeric_convert(value, scu * COMMODITY_DENOM_MULT,
|
||||||
value = gnc_numeric_convert(value, scu * COMMODITY_DENOM_MULT,
|
GNC_HOW_RND_ROUND_HALF_UP);
|
||||||
GNC_HOW_RND_ROUND_HALF_UP);
|
|
||||||
gnc_price_begin_edit (price);
|
gnc_price_begin_edit (price);
|
||||||
gnc_price_set_time (price, ts);
|
gnc_price_set_time (price, ts);
|
||||||
gnc_price_set_source (price, PRICE_SOURCE_SPLIT_REG);
|
gnc_price_set_source (price, PRICE_SOURCE_SPLIT_REG);
|
||||||
|
Loading…
Reference in New Issue
Block a user