diff options
author | John Wiegley <johnw@newartisans.com> | 2012-03-07 05:20:42 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-03-07 05:20:42 -0600 |
commit | 76f97a63da2deb8b6f9f8129bb11f5608d4a5518 (patch) | |
tree | ae46855b1573cdc4d0441def3b126aae702d8064 /src/post.cc | |
parent | 69b25d367ed2317a537aefa9744ca315b5422fa5 (diff) | |
download | fork-ledger-76f97a63da2deb8b6f9f8129bb11f5608d4a5518.tar.gz fork-ledger-76f97a63da2deb8b6f9f8129bb11f5608d4a5518.tar.bz2 fork-ledger-76f97a63da2deb8b6f9f8129bb11f5608d4a5518.zip |
Added parsing support for the many value directives
Diffstat (limited to 'src/post.cc')
-rw-r--r-- | src/post.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/post.cc b/src/post.cc index 191a9142..7a6667f2 100644 --- a/src/post.cc +++ b/src/post.cc @@ -36,6 +36,7 @@ #include "account.h" #include "journal.h" #include "format.h" +#include "pool.h" namespace ledger { @@ -638,6 +639,43 @@ void post_t::set_reported_account(account_t * acct) acct->xdata().reported_posts.push_back(this); } +void extend_post(post_t& post, journal_t& journal) +{ + commodity_t& comm(post.amount.commodity()); + + annotation_t * details = + (comm.has_annotation() ? + &as_annotated_commodity(comm).details : NULL); + + if (! details || ! details->value_expr) { + optional<expr_t> value_expr; + + if (optional<value_t> data = post.get_tag(_("Value"))) + value_expr = expr_t(data->to_string()); + + if (! value_expr) + value_expr = post.account->value_expr; + + if (! value_expr) + value_expr = post.amount.commodity().value_expr(); + + if (! value_expr) + value_expr = journal.value_expr; + + if (value_expr) { + if (! details) { + annotation_t new_details; + new_details.value_expr = value_expr; + commodity_t * new_comm = + commodity_pool_t::current_pool->find_or_create(comm, new_details); + post.amount.set_commodity(*new_comm); + } else { + details->value_expr = value_expr; + } + } + } +} + void to_xml(std::ostream& out, const post_t& post) { push_xml x(out, "posting", true); |