diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-12 21:39:28 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-13 01:03:48 -0400 |
commit | 8d2fce1ae8a1b8c3cce4e22d807421915a0001ce (patch) | |
tree | 6d71920ff303e3a70b6a2ae89b21a8c8e8372913 /src/xact.cc | |
parent | 5ec85538d9690634a2b1ee7c422e109700eb0627 (diff) | |
download | fork-ledger-8d2fce1ae8a1b8c3cce4e22d807421915a0001ce.tar.gz fork-ledger-8d2fce1ae8a1b8c3cce4e22d807421915a0001ce.tar.bz2 fork-ledger-8d2fce1ae8a1b8c3cce4e22d807421915a0001ce.zip |
Automated xacts may now contain "deferred tags"
For example, consider the following automated transaction:
= /Food/
; Next Date:: date + 10
(Expenses:Tax) 1.00
; Next Date:: date + 20
This will add a metadata field named 'Next Date' to the _matching
posting_, with a value that is 10 days later than that posting. It will
also generate a new posting for that transaction, whose amount is the
same as the matching posting. Further, it will add a 'Next Date'
metadata tag to the _generated posting_ whose value is 20 days later
than the date of the matching posting.
Diffstat (limited to 'src/xact.cc')
-rw-r--r-- | src/xact.cc | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/xact.cc b/src/xact.cc index 3b66598c..77d87ae9 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -634,7 +634,8 @@ namespace { } // unnamed namespace -void auto_xact_t::extend_xact(xact_base_t& xact) +void auto_xact_t::extend_xact(xact_base_t& xact, + optional<date_t::year_type> current_year) { posts_list initial_posts(xact.posts.begin(), xact.posts.end()); @@ -679,6 +680,18 @@ void auto_xact_t::extend_xact(xact_base_t& xact) matches_predicate = predicate(*initial_post); } if (matches_predicate) { + bind_scope_t bound_scope(*scope_t::default_scope, *initial_post); + + if (deferred_notes) { + foreach (deferred_tag_data_t& data, *deferred_notes) { + if (data.apply_to_post == NULL) + initial_post->parse_tags(data.tag_data.c_str(), + bound_scope, + data.overwrite_existing, + current_year); + } + } + foreach (post_t * post, posts) { amount_t post_amount; if (post->amount.is_null()) { @@ -686,7 +699,6 @@ void auto_xact_t::extend_xact(xact_base_t& xact) throw_(amount_error, _("Automated transaction's posting has no amount")); - bind_scope_t bound_scope(*scope_t::default_scope, *initial_post); value_t result(post->amount_expr->calc(bound_scope)); if (result.is_long()) { post_amount = result.to_amount(); @@ -752,6 +764,16 @@ void auto_xact_t::extend_xact(xact_base_t& xact) if (new_post->must_balance()) needs_further_verification = true; + + if (deferred_notes) { + foreach (deferred_tag_data_t& data, *deferred_notes) { + if (data.apply_to_post == post) + new_post->parse_tags(data.tag_data.c_str(), + bound_scope, + data.overwrite_existing, + current_year); + } + } } } } |