summaryrefslogtreecommitdiff
path: root/src/xact.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/xact.cc')
-rw-r--r--src/xact.cc57
1 files changed, 44 insertions, 13 deletions
diff --git a/src/xact.cc b/src/xact.cc
index f05c6069..4e8e56fa 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -269,11 +269,13 @@ 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) {
if (breakdown.basis_cost.commodity() == breakdown.final_cost.commodity()) {
+ DEBUG("xact.finalize", "breakdown.basis_cost = " << breakdown.basis_cost);
+ DEBUG("xact.finalize", "breakdown.final_cost = " << breakdown.final_cost);
if (amount_t gain_loss = breakdown.basis_cost - breakdown.final_cost) {
DEBUG("xact.finalize", "gain_loss = " << gain_loss);
gain_loss.in_place_round();
@@ -329,13 +331,24 @@ bool xact_base_t::finalize()
if (balance.is_balance()) {
const balance_t& bal(balance.as_balance());
- typedef std::map<string, amount_t> sorted_amounts_map;
+#if 1
+ typedef std::map<std::pair<string, annotation_t>,
+ amount_t> sorted_amounts_map;
sorted_amounts_map samp;
foreach (const balance_t::amounts_map::value_type& pair, bal.amounts) {
+#if defined(DEBUG_ON)
std::pair<sorted_amounts_map::iterator, bool> result =
- samp.insert(sorted_amounts_map::value_type(pair.first->mapping_key(),
- pair.second));
+#endif
+ samp.insert(sorted_amounts_map::value_type
+ (sorted_amounts_map::key_type
+ (pair.first->symbol(),
+ pair.first->has_annotation() ?
+ as_annotated_commodity(*pair.first).details :
+ annotation_t()),
+ pair.second));
+#if defined(DEBUG_ON)
assert(result.second);
+#endif
}
bool first = true;
@@ -351,6 +364,21 @@ bool xact_base_t::finalize()
add_post(p);
}
}
+#else
+ bool first = true;
+ foreach (const balance_t::amounts_map::value_type& pair, bal.amounts) {
+ if (first) {
+ null_post->amount = pair.second.negated();
+ null_post->add_flags(POST_CALCULATED);
+ first = false;
+ } else {
+ post_t * p = new post_t(null_post->account, pair.second.negated(),
+ ITEM_GENERATED | POST_CALCULATED);
+ p->set_state(null_post->state());
+ add_post(p);
+ }
+ }
+#endif
}
else if (balance.is_amount()) {
null_post->amount = balance.as_amount().negated();
@@ -749,22 +777,25 @@ void auto_xact_t::extend_xact(xact_base_t& xact, parse_context_t& context)
post_t * new_post = new post_t(account, amt);
new_post->copy_details(*post);
new_post->add_flags(ITEM_GENERATED);
-
- // jww (2012-02-27): Do account directive assertions get applied
- // to postings generated from automated transactions?
- xact.add_post(new_post);
- new_post->account->add_post(new_post);
-
- if (new_post->must_balance())
- needs_further_verification = true;
+ new_post->account =
+ journal->register_account(account->fullname(), new_post,
+ journal->master);
if (deferred_notes) {
foreach (deferred_tag_data_t& data, *deferred_notes) {
- if (data.apply_to_post == post)
+ if (! data.apply_to_post || data.apply_to_post == post)
new_post->parse_tags(data.tag_data.c_str(), bound_scope,
data.overwrite_existing);
}
}
+
+ extend_post(*new_post, *journal);
+
+ xact.add_post(new_post);
+ new_post->account->add_post(new_post);
+
+ if (new_post->must_balance())
+ needs_further_verification = true;
}
}
}