diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-25 04:32:30 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-25 04:39:59 -0500 |
commit | 2c90c10db17a1e379639f2aa5e7c47fcb351d9f7 (patch) | |
tree | 136adb3762bfbc58f28667b74a9aa2eca4ae431a /src/pool.cc | |
parent | a7424c1df9b565e77ff25fee46f8a79d2638f42c (diff) | |
download | fork-ledger-2c90c10db17a1e379639f2aa5e7c47fcb351d9f7.tar.gz fork-ledger-2c90c10db17a1e379639f2aa5e7c47fcb351d9f7.tar.bz2 fork-ledger-2c90c10db17a1e379639f2aa5e7c47fcb351d9f7.zip |
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
Diffstat (limited to 'src/pool.cc')
-rw-r--r-- | src/pool.cc | 16 |
1 files changed, 10 insertions, 6 deletions
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<price_point_t> commodity_pool_t::parse_price_directive(char * line) +optional<std::pair<commodity_t *, price_point_t> > +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<price_point_t> 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<price_point_t> 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<price_point_t> 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_t *, price_point_t>(commodity, point); } return none; |