diff options
author | John Wiegley <johnw@newartisans.com> | 2012-03-10 02:27:33 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-03-10 02:27:33 -0600 |
commit | 080c1d9a2d0f3013a4d26879a3e98cfa62ef3e48 (patch) | |
tree | b95c15c1dc13925bcc4b3c11d98c06c50bba1bcc /src | |
parent | 50f202c4e8faecf7398fb21ba5b31768ec46c826 (diff) | |
download | fork-ledger-080c1d9a2d0f3013a4d26879a3e98cfa62ef3e48.tar.gz fork-ledger-080c1d9a2d0f3013a4d26879a3e98cfa62ef3e48.tar.bz2 fork-ledger-080c1d9a2d0f3013a4d26879a3e98cfa62ef3e48.zip |
Added syntactic sugar for lot pricing: {{$500.00}}
Diffstat (limited to 'src')
-rw-r--r-- | src/amount.cc | 12 | ||||
-rw-r--r-- | src/annotate.cc | 20 | ||||
-rw-r--r-- | src/annotate.h | 7 |
3 files changed, 29 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; |