summaryrefslogtreecommitdiff
path: root/src/commodity.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-03-02 16:39:26 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-03-02 16:39:26 -0400
commit1c7de0f9e4d6372ab80a90f0ccd8ce7314466686 (patch)
tree48aa139446af98005c983b94de70d73acdf3d61c /src/commodity.cc
parentc10c01e5a5eef1963d5ba7d97831e3185fb7cf30 (diff)
downloadfork-ledger-1c7de0f9e4d6372ab80a90f0ccd8ce7314466686.tar.gz
fork-ledger-1c7de0f9e4d6372ab80a90f0ccd8ce7314466686.tar.bz2
fork-ledger-1c7de0f9e4d6372ab80a90f0ccd8ce7314466686.zip
Added "fixated commodity pricing"
If you put '=' before an annotated commodity's price, it will cause any future market valuation of that commodity to use that price, and ignore whatever changes may have happened since in the market price. This can be useful if you are tracking gas expenses based on a standard rate which, although it changes over time, should not adjust the historical valuation of how much the gas cost at the time it was purchased: 2009/01/01 Payee Expenses:Gas 100 GAL {=$2} Liabilities:MasterCard $-200
Diffstat (limited to 'src/commodity.cc')
-rw-r--r--src/commodity.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/commodity.cc b/src/commodity.cc
index 1c849624..08252cf4 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -638,6 +638,12 @@ void annotation_t::parse(std::istream& in)
throw_(amount_error, _("Commodity specifies more than one price"));
in.get(c);
+ c = peek_next_nonws(in);
+ if (c == '=') {
+ in.get(c);
+ add_flags(ANNOTATION_PRICE_FIXATED);
+ }
+
READ_INTO(in, buf, 255, c, c != '}');
if (c == '}')
in.get(c);
@@ -761,7 +767,10 @@ void annotated_commodity_t::write_annotations(std::ostream& out) const
void annotation_t::print(std::ostream& out, bool keep_base) const
{
if (price)
- out << " {" << (keep_base ? *price : price->unreduced()).rounded() << '}';
+ out << " {"
+ << (has_flags(ANNOTATION_PRICE_FIXATED) ? "=" : "")
+ << (keep_base ? *price : price->unreduced()).rounded()
+ << '}';
if (date)
out << " [" << format_date(*date, string("%Y/%m/%d")) << ']';