-G option now takes price history into account

This commit is contained in:
John Wiegley 2010-05-30 21:58:05 -06:00
parent 5a2644c1b7
commit 654c842348
3 changed files with 56 additions and 6 deletions

View file

@ -582,20 +582,68 @@ void changed_value_posts::output_intermediate_prices(post_t& post,
// date. If so, generate an output_revaluation for that price change.
// Mostly this is only going to occur if the user has a series of pricing
// entries, since a posting-based revaluation would be seen here as a post.
assert(! last_total.is_null());
switch (last_total.type()) {
value_t display_total(last_total);
if (display_total.type() == value_t::SEQUENCE) {
xact_t& xact(temps.create_xact());
xact.payee = _("Commodities revalued");
xact._date = is_valid(current) ? current : post.date();
post_t& temp(temps.copy_post(post, xact));
temp.add_flags(ITEM_GENERATED);
post_t::xdata_t& xdata(temp.xdata());
if (is_valid(current))
xdata.date = current;
DEBUG("filters.revalued", "intermediate last_total = " << last_total);
switch (last_total.type()) {
case value_t::BOOLEAN:
case value_t::INTEGER:
last_total.in_place_cast(value_t::AMOUNT);
// fall through...
case value_t::AMOUNT:
temp.amount = last_total.as_amount();
break;
case value_t::BALANCE:
case value_t::SEQUENCE:
xdata.compound_value = last_total;
xdata.add_flags(POST_EXT_COMPOUND);
break;
case value_t::DATETIME:
case value_t::DATE:
default:
assert(false);
break;
}
bind_scope_t inner_scope(report, temp);
display_total = display_total_expr.calc(inner_scope);
DEBUG("filters.revalued", "intermediate display_total = " << display_total);
}
switch (display_total.type()) {
case value_t::VOID:
case value_t::INTEGER:
case value_t::SEQUENCE:
break;
case value_t::AMOUNT:
last_total.in_place_cast(value_t::BALANCE);
display_total.in_place_cast(value_t::BALANCE);
// fall through...
case value_t::BALANCE: {
commodity_t::history_map all_prices;
foreach (const balance_t::amounts_map::value_type& amt_comm,
last_total.as_balance().amounts) {
display_total.as_balance().amounts) {
if (optional<commodity_t::varied_history_t&> hist =
amt_comm.first->varied_history()) {
foreach

View file

@ -50,7 +50,8 @@ P 2010/03/01 00:00:00 S 8 P
P 2010/04/01 00:00:00 S 16 P
>>>1
09-Jan-01 Sample 1a As:Brokerage:Stocks 0 0
09-Feb-01 Commodities revalued <Revalued> 300 P 300 P
09-Jan-15 Commodities revalued <Revalued> 100 P 100 P
09-Feb-01 Commodities revalued <Revalued> 200 P 300 P
09-Feb-01 Sample 2a As:Brokerage:Stocks 300 P 600 P
09-Mar-01 Commodities revalued <Revalued> 800 P 1400 P
09-Mar-01 Sample 3a As:Brokerage:Stocks 700 P 2100 P

View file

@ -37,7 +37,8 @@ reg --end 2009/06/26 -G equities
08-Jan-01 Purchase Apple shares Equities 0 0
08-Jun-30 Commodities revalued <Revalued> $500 $500
08-Jun-30 Sell some Apple sha.. Equities 0 $500
09-Jun-26 Commodities revalued <Revalued> $750 $1250
09-Jan-31 Commodities revalued <Revalued> $250 $750
09-Jun-26 Commodities revalued <Revalued> $500 $1250
>>>2
=== 0
reg -I equities