Changed the semantics of the "prices" report

The prices report now uses the following scheme:

    PAYEE   -> name of commodity of price
    ACCOUNT -> name of commodity of item
    AMOUNT  -> price
    DATE    -> date of pricing

However, the report does not show the payee.  The only reason the payee
is set is to enable clever querying.  For example:

    ledger prices gold        # show all known prices for GOLD
    ledger prices @gold       # show all known prices *in* GOLD
This commit is contained in:
John Wiegley 2009-02-13 19:30:53 -04:00
parent 326cbea4c7
commit a87ed245d7
2 changed files with 23 additions and 10 deletions

View file

@ -85,32 +85,46 @@ void xacts_commodities_iterator::reset(journal_t& journal)
commodities.insert(&comm);
}
std::map<string, entry_t *> entries_by_commodity;
foreach (commodity_t * comm, commodities) {
optional<commodity_t::varied_history_t&> history = comm->varied_history();
if (! history)
continue;
entry_temps.push_back(new entry_t);
entry_temps.back()->payee = comm->symbol();
entry_temps.back()->_date = CURRENT_DATE();
account_t * account = journal.master->find_account(comm->symbol());
foreach (commodity_t::base_t::history_by_commodity_map::value_type pair,
history->histories) {
commodity_t& price_comm(*pair.first);
commodity_t::history_t& price_hist(pair.second);
acct_temps.push_back(account_t(NULL, price_comm.symbol()));
foreach (commodity_t::base_t::history_map::value_type hpair,
price_hist.prices) {
xact_temps.push_back(xact_t(&acct_temps.back()));
entry_t * entry;
string symbol = hpair.second.commodity().symbol();
std::map<string, entry_t *>::iterator i =
entries_by_commodity.find(symbol);
if (i != entries_by_commodity.end()) {
entry = (*i).second;
} else {
entry_temps.push_back(new entry_t);
entry = entry_temps.back();
entry->payee = symbol;
entry->_date = hpair.first.date();
entries_by_commodity.insert
(std::pair<string, entry_t *>(symbol, entry));
}
xact_temps.push_back(xact_t(account));
xact_t& temp = xact_temps.back();
temp._date = hpair.first.date();
temp.entry = entry_temps.back();
temp.entry = entry;
temp.amount = hpair.second;
temp.set_flags(ITEM_GENERATED | ITEM_TEMP);
entry_temps.back()->add_xact(&temp);
entry->add_xact(&temp);
}
}
}

View file

@ -80,8 +80,7 @@ report_t::report_t(session_t& _session)
HANDLER(plot_total_format_).on("%D %(S(T))\n");
HANDLER(prices_format_).on(
"%-.9(date) %-.10(payee) %-10(account) %12(strip(display_amount))\n%/"
"%21|%-.9(date) %-.10(payee) %-10(account) %12(strip(display_amount))\n");
"%-.9(date) %-8(account) %12(strip(display_amount))\n");
HANDLER(pricesdb_format_).on("P %[%Y/%m/%d %H:%M:%S] %A %t\n");
HANDLER(csv_format_).on(