summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/amount.cc12
-rw-r--r--src/annotate.cc20
-rw-r--r--src/annotate.h7
-rw-r--r--test/baseline/feat-annotations.test37
4 files changed, 66 insertions, 10 deletions
diff --git a/src/amount.cc b/src/amount.cc
index d1aa1655..46eb5531 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -1065,10 +1065,6 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
if (! commodity_)
commodity_ = commodity_pool_t::current_pool->create(symbol);
assert(commodity_);
-
- if (details)
- commodity_ =
- commodity_pool_t::current_pool->find_or_create(*commodity_, details);
}
// Quickly scan through and verify the correctness of the amount's use of
@@ -1204,6 +1200,14 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
if (! flags.has_flags(PARSE_NO_REDUCE))
in_place_reduce(); // will not throw an exception
+ if (commodity_ && details) {
+ if (details.has_flags(ANNOTATION_PRICE_NOT_PER_UNIT)) {
+ assert(details.price);
+ *details.price /= this->abs();
+ }
+ set_commodity(*commodity_pool_t::current_pool->find_or_create(*commodity_, details));
+ }
+
VERIFY(valid());
return true;
diff --git a/src/annotate.cc b/src/annotate.cc
index 1140bf0a..d2c7f983 100644
--- a/src/annotate.cc
+++ b/src/annotate.cc
@@ -88,6 +88,12 @@ void annotation_t::parse(std::istream& in)
throw_(amount_error, _("Commodity specifies more than one price"));
in.get(c);
+ c = static_cast<char>(in.peek());
+ if (c == '{') {
+ in.get(c);
+ add_flags(ANNOTATION_PRICE_NOT_PER_UNIT);
+ }
+
c = peek_next_nonws(in);
if (c == '=') {
in.get(c);
@@ -95,10 +101,18 @@ void annotation_t::parse(std::istream& in)
}
READ_INTO(in, buf, 255, c, c != '}');
- if (c == '}')
+ if (c == '}') {
in.get(c);
- else
- throw_(amount_error, _("Commodity price lacks closing brace"));
+ if (has_flags(ANNOTATION_PRICE_NOT_PER_UNIT)) {
+ c = static_cast<char>(in.peek());
+ if (c != '}')
+ throw_(amount_error, _("Commodity lot price lacks double closing brace"));
+ else
+ in.get(c);
+ }
+ } else {
+ throw_(amount_error, _("Commodity lot price lacks closing brace"));
+ }
amount_t temp;
temp.parse(buf, PARSE_NO_MIGRATE);
diff --git a/src/annotate.h b/src/annotate.h
index 22c3d8ad..606c6a60 100644
--- a/src/annotate.h
+++ b/src/annotate.h
@@ -55,9 +55,10 @@ struct annotation_t : public supports_flags<>,
{
#define ANNOTATION_PRICE_CALCULATED 0x01
#define ANNOTATION_PRICE_FIXATED 0x02
-#define ANNOTATION_DATE_CALCULATED 0x04
-#define ANNOTATION_TAG_CALCULATED 0x08
-#define ANNOTATION_VALUE_EXPR_CALCULATED 0x10
+#define ANNOTATION_PRICE_NOT_PER_UNIT 0x04
+#define ANNOTATION_DATE_CALCULATED 0x08
+#define ANNOTATION_TAG_CALCULATED 0x10
+#define ANNOTATION_VALUE_EXPR_CALCULATED 0x20
optional<amount_t> price;
optional<date_t> date;
diff --git a/test/baseline/feat-annotations.test b/test/baseline/feat-annotations.test
new file mode 100644
index 00000000..18f5d7d9
--- /dev/null
+++ b/test/baseline/feat-annotations.test
@@ -0,0 +1,37 @@
+2012-03-09 KFC
+ Expenses:Food 10 CHIK @ $50
+ Assets:Cash
+
+2012-03-09 KFC
+ Assets:Cash $75
+ Expenses:Food -10 CHIK {{$50}} @ $75
+ Equity:Capital Gains $-25
+
+2012-03-09 KFC
+ Expenses:Food 10 CHIK
+ Assets:Cash $-50
+
+2012-03-09 KFC
+ Assets:Cash $75
+ Expenses:Food -10 CHIK {{$50}}
+ Equity:Capital Gains $-25
+
+test print
+2012/03/09 KFC
+ Expenses:Food 10 CHIK @ $50
+ Assets:Cash
+
+2012/03/09 KFC
+ Assets:Cash $75
+ Expenses:Food -10 CHIK {$5} @ $75
+ Equity:Capital Gains $-25
+
+2012/03/09 KFC
+ Expenses:Food 10 CHIK
+ Assets:Cash $-50
+
+2012/03/09 KFC
+ Assets:Cash $75
+ Expenses:Food -10 CHIK {$5}
+ Equity:Capital Gains $-25
+end test