From 2c90c10db17a1e379639f2aa5e7c47fcb351d9f7 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 25 Nov 2009 04:32:30 -0500 Subject: Added support for a "fixed" directive It lets you specify a fixed cost for a duration of a ledger file, for example: fixed ecu $2 2008/01/01 income assets:bank:checking 1 ecu income:salary end fixed This is equivalent to: 2008/01/01 income assets:bank:checking 1 ecu {=$2} income:salary --- src/pool.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/pool.cc') diff --git a/src/pool.cc b/src/pool.cc index 00f4a3da..70f4eed6 100644 --- a/src/pool.cc +++ b/src/pool.cc @@ -286,7 +286,8 @@ commodity_pool_t::exchange(const amount_t& amount, return breakdown; } -optional commodity_pool_t::parse_price_directive(char * line) +optional > +commodity_pool_t::parse_price_directive(char * line, bool do_not_add_price) { char * date_field_ptr = line; char * time_field_ptr = next_element(date_field_ptr); @@ -295,6 +296,7 @@ optional commodity_pool_t::parse_price_directive(char * line) char * symbol_and_price; datetime_t datetime; + string symbol; if (std::isdigit(time_field_ptr[0])) { symbol_and_price = next_element(time_field_ptr); @@ -307,12 +309,13 @@ optional commodity_pool_t::parse_price_directive(char * line) datetime = datetime_t(parse_date(date_field)); } else { - symbol_and_price = date_field_ptr; + symbol = date_field_ptr; + symbol_and_price = time_field_ptr; datetime = CURRENT_TIME(); } - string symbol; - commodity_t::parse_symbol(symbol_and_price, symbol); + if (symbol.empty()) + commodity_t::parse_symbol(symbol_and_price, symbol); price_point_t point; point.when = datetime; @@ -323,9 +326,10 @@ optional commodity_pool_t::parse_price_directive(char * line) if (commodity_t * commodity = find_or_create(symbol)) { DEBUG("commodity.download", "Adding price for " << symbol << ": " << point.when << " " << point.price); - commodity->add_price(point.when, point.price, true); + if (! do_not_add_price) + commodity->add_price(point.when, point.price, true); commodity->add_flags(COMMODITY_KNOWN); - return point; + return std::pair(commodity, point); } return none; -- cgit v1.2.3