summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-03-09 01:28:20 -0600
committerJohn Wiegley <johnw@newartisans.com>2012-03-09 01:28:20 -0600
commitc9f7195936090ecbe2d5b4ec88c196660ae24f81 (patch)
tree7bfbe9d00de44c0c79c460169ad324b6a17c6379 /src
parent9f81c798ee0854cab038714670123bff6676a5d5 (diff)
downloadfork-ledger-c9f7195936090ecbe2d5b4ec88c196660ae24f81.tar.gz
fork-ledger-c9f7195936090ecbe2d5b4ec88c196660ae24f81.tar.bz2
fork-ledger-c9f7195936090ecbe2d5b4ec88c196660ae24f81.zip
Added the notion of "virtual costs"
Diffstat (limited to 'src')
-rw-r--r--src/annotate.cc7
-rw-r--r--src/pool.cc1
-rw-r--r--src/pool.h1
-rw-r--r--src/post.h3
-rw-r--r--src/py_commodity.cc7
-rw-r--r--src/textual.cc11
-rw-r--r--src/xact.cc2
7 files changed, 24 insertions, 8 deletions
diff --git a/src/annotate.cc b/src/annotate.cc
index d2e4976e..1140bf0a 100644
--- a/src/annotate.cc
+++ b/src/annotate.cc
@@ -122,7 +122,12 @@ void annotation_t::parse(std::istream& in)
else if (c == '(') {
in.get(c);
c = static_cast<char>(in.peek());
- if (c == '(') {
+ if (c == '@') {
+ in.clear();
+ in.seekg(pos, std::ios::beg);
+ break;
+ }
+ else if (c == '(') {
if (value_expr)
throw_(amount_error,
_("Commodity specifies more than one valuation expresion"));
diff --git a/src/pool.cc b/src/pool.cc
index fd661fe1..1dd91e99 100644
--- a/src/pool.cc
+++ b/src/pool.cc
@@ -246,6 +246,7 @@ cost_breakdown_t
commodity_pool_t::exchange(const amount_t& amount,
const amount_t& cost,
const bool is_per_unit,
+ const bool add_price,
const optional<datetime_t>& moment,
const optional<string>& tag)
{
diff --git a/src/pool.h b/src/pool.h
index 7203bc20..b7921f59 100644
--- a/src/pool.h
+++ b/src/pool.h
@@ -119,6 +119,7 @@ public:
cost_breakdown_t exchange(const amount_t& amount,
const amount_t& cost,
const bool is_per_unit = false,
+ const bool add_price = true,
const optional<datetime_t>& moment = none,
const optional<string>& tag = none);
diff --git a/src/post.h b/src/post.h
index 217f5509..7d93b1cc 100644
--- a/src/post.h
+++ b/src/post.h
@@ -58,7 +58,8 @@ public:
#define POST_COST_CALCULATED 0x0080 // posting's cost was calculated
#define POST_COST_IN_FULL 0x0100 // cost specified using @@
#define POST_COST_FIXATED 0x0200 // cost is fixed using = indicator
-#define POST_ANONYMIZED 0x0400 // a temporary, anonymous posting
+#define POST_COST_VIRTUAL 0x0400 // cost is virtualized: (@)
+#define POST_ANONYMIZED 0x0800 // a temporary, anonymous posting
xact_t * xact; // only set for posts of regular xacts
account_t * account;
diff --git a/src/py_commodity.cc b/src/py_commodity.cc
index 25e5b918..c75b5e64 100644
--- a/src/py_commodity.cc
+++ b/src/py_commodity.cc
@@ -96,14 +96,15 @@ namespace {
pool.exchange(commodity, per_unit_cost, moment);
}
- cost_breakdown_t py_exchange_5(commodity_pool_t& pool,
+ cost_breakdown_t py_exchange_7(commodity_pool_t& pool,
const amount_t& amount,
const amount_t& cost,
const bool is_per_unit,
+ const bool add_prices,
const boost::optional<datetime_t>& moment,
const boost::optional<string>& tag)
{
- return pool.exchange(amount, cost, is_per_unit, moment, tag);
+ return pool.exchange(amount, cost, is_per_unit, add_prices, moment, tag);
}
commodity_t * py_pool_getitem(commodity_pool_t& pool, const string& symbol)
@@ -280,7 +281,7 @@ void export_commodity()
.def("exchange", py_exchange_2, with_custodian_and_ward<1, 2>())
.def("exchange", py_exchange_3, with_custodian_and_ward<1, 2>())
- .def("exchange", py_exchange_5)
+ .def("exchange", py_exchange_7)
.def("parse_price_directive", &commodity_pool_t::parse_price_directive)
.def("parse_price_expression", &commodity_pool_t::parse_price_expression,
diff --git a/src/textual.cc b/src/textual.cc
index 66972fb3..a8cb844b 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -1447,12 +1447,16 @@ post_t * instance_t::parse_post(char * line,
// Parse the optional cost (@ PER-UNIT-COST, @@ TOTAL-COST)
- if (*next == '@') {
+ if (*next == '@' || (*next == '(' && *(next + 1) == '@')) {
DEBUG("textual.parse", "line " << context.linenum << ": "
<< "Found a price indicator");
- bool per_unit = true;
+ if (*next == '(') {
+ post->add_flags(POST_COST_VIRTUAL);
+ ++next;
+ }
+ bool per_unit = true;
if (*++next == '@') {
per_unit = false;
post->add_flags(POST_COST_IN_FULL);
@@ -1460,6 +1464,9 @@ post_t * instance_t::parse_post(char * line,
<< "And it's for a total price");
}
+ if (post->has_flags(POST_COST_VIRTUAL) && *(next + 1) == ')')
+ ++next;
+
beg = static_cast<std::streamsize>(++next - line);
p = skip_ws(next);
diff --git a/src/xact.cc b/src/xact.cc
index 4e43e680..4e8e56fa 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -269,7 +269,7 @@ bool xact_base_t::finalize()
cost_breakdown_t breakdown =
commodity_pool_t::current_pool->exchange
- (post->amount, *post->cost, false,
+ (post->amount, *post->cost, false, ! post->has_flags(POST_COST_VIRTUAL),
datetime_t(date(), time_duration(0, 0, 0, 0)));
if (post->amount.has_annotation() && post->amount.annotation().price) {