mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Edit split-based prices instead of adding.
For split-register and xfer-dialog generated prices if there's an existing non-FQ price for the day, change it. If there's an F::Q quote for the day, do nothing. Only add a price if there isn't one for the from/to combination.
This commit is contained in:
parent
5e609dac0d
commit
966789374d
@ -86,7 +86,7 @@ struct _xferDialog
|
||||
gnc_commodity *to_commodity;
|
||||
|
||||
QuickFill *qf; /* Quickfill on transfer descriptions,
|
||||
defaults to matching on the "From" account. */
|
||||
defaults to matching on the "From" account. */
|
||||
|
||||
XferDirection quickfill; /* direction match on the account instead. */
|
||||
|
||||
@ -1549,26 +1549,46 @@ create_price(XferDialog *xferData, Timespec ts)
|
||||
}
|
||||
}
|
||||
|
||||
if (price && gnc_numeric_equal(value, price_value))
|
||||
if (price)
|
||||
{
|
||||
PINFO("Found price for %s in %s", gnc_commodity_get_mnemonic(from),
|
||||
gnc_commodity_get_mnemonic(to));
|
||||
}
|
||||
else
|
||||
{
|
||||
price = gnc_price_create (xferData->book);
|
||||
if (gnc_numeric_equal(value, price_value))
|
||||
{
|
||||
PINFO("Found price for %s in %s", gnc_commodity_get_mnemonic(from),
|
||||
gnc_commodity_get_mnemonic(to));
|
||||
gnc_price_unref (price);
|
||||
return;
|
||||
}
|
||||
if (strcmp (gnc_price_get_source(price), PRICE_SOURCE_FQ) == 0)
|
||||
{
|
||||
PINFO("Existing price is from Finance::Quote, so won't supersede.");
|
||||
gnc_price_unref (price);
|
||||
return;
|
||||
}
|
||||
if (!gnc_numeric_eq(price_value, gnc_price_get_value(price)))
|
||||
value = gnc_numeric_div (gnc_numeric_create(1, 1), value,
|
||||
PRECISION, GNC_HOW_DENOM_REDUCE);
|
||||
|
||||
gnc_price_begin_edit (price);
|
||||
gnc_price_set_commodity (price, from);
|
||||
gnc_price_set_currency (price, to);
|
||||
gnc_price_set_time (price, ts);
|
||||
gnc_price_set_source (price, PRICE_SOURCE_XFER_DLG);
|
||||
gnc_price_set_value (price, value);
|
||||
gnc_pricedb_add_price (xferData->pricedb, price);
|
||||
gnc_price_commit_edit (price);
|
||||
PINFO("Created price: 1 %s = %f %s", gnc_commodity_get_mnemonic(from),
|
||||
PINFO("Modified price: 1 %s = %f %s", gnc_commodity_get_mnemonic(from),
|
||||
gnc_numeric_to_double(value), gnc_commodity_get_mnemonic(to));
|
||||
gnc_price_unref (price);
|
||||
return;
|
||||
}
|
||||
|
||||
price = gnc_price_create (xferData->book);
|
||||
gnc_price_begin_edit (price);
|
||||
gnc_price_set_commodity (price, from);
|
||||
gnc_price_set_currency (price, to);
|
||||
gnc_price_set_time (price, ts);
|
||||
gnc_price_set_source (price, PRICE_SOURCE_XFER_DLG);
|
||||
gnc_price_set_value (price, value);
|
||||
gnc_pricedb_add_price (xferData->pricedb, price);
|
||||
gnc_price_commit_edit (price);
|
||||
PINFO("Created price: 1 %s = %f %s", gnc_commodity_get_mnemonic(from),
|
||||
gnc_numeric_to_double(value), gnc_commodity_get_mnemonic(to));
|
||||
gnc_price_unref (price);
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,7 @@ static QofLogModule log_module = GNC_MOD_LEDGER;
|
||||
static CursorClass copied_class = CURSOR_CLASS_NONE;
|
||||
static SCM copied_item = SCM_UNDEFINED;
|
||||
static GncGUID copied_leader_guid;
|
||||
static const int PRECISION = 1000000;
|
||||
|
||||
|
||||
/** static prototypes *****************************************************/
|
||||
@ -2078,9 +2079,31 @@ record_price (SplitRegister *reg, Account *account, gnc_numeric value)
|
||||
GNC_HOW_DENOM_REDUCE);
|
||||
}
|
||||
}
|
||||
if (price)
|
||||
{
|
||||
if (gnc_numeric_equal(value, price_value))
|
||||
{
|
||||
gnc_price_unref (price);
|
||||
return;
|
||||
}
|
||||
if (strcmp (gnc_price_get_source(price), PRICE_SOURCE_FQ) == 0)
|
||||
{
|
||||
gnc_price_unref(price);
|
||||
return;
|
||||
}
|
||||
if (!gnc_numeric_eq(price_value, gnc_price_get_value(price)))
|
||||
value = gnc_numeric_div (gnc_numeric_create(1, 1), value,
|
||||
PRECISION, GNC_HOW_DENOM_REDUCE);
|
||||
|
||||
if (price && gnc_numeric_equal(value, price_value))
|
||||
gnc_price_begin_edit (price);
|
||||
gnc_price_set_time (price, ts);
|
||||
gnc_price_set_source (price, PRICE_SOURCE_SPLIT_REG);
|
||||
gnc_price_set_value (price, value);
|
||||
gnc_price_commit_edit (price);
|
||||
gnc_price_unref (price);
|
||||
return;
|
||||
}
|
||||
|
||||
price = gnc_price_create (book);
|
||||
gnc_price_begin_edit (price);
|
||||
gnc_price_set_commodity (price, comm);
|
||||
@ -2566,7 +2589,7 @@ gnc_split_register_config_cells (SplitRegister *reg)
|
||||
/* Use 6 decimal places for prices and "exchange rates" */
|
||||
gnc_price_cell_set_fraction
|
||||
((PriceCell *)
|
||||
gnc_table_layout_get_cell (reg->table->layout, PRIC_CELL), 1000000);
|
||||
gnc_table_layout_get_cell (reg->table->layout, PRIC_CELL), PRECISION);
|
||||
|
||||
/* Initialize shares and share balance cells */
|
||||
gnc_price_cell_set_print_info
|
||||
|
Loading…
Reference in New Issue
Block a user