diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-10 16:33:46 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-10 16:33:46 -0400 |
commit | ab749742d9ccadc087e412187ee3a9d262aed475 (patch) | |
tree | 4e43bbd051e58f50de331c4d564d5ef023abcf9a | |
parent | 92d2eb957407c16d1eca3598e00e6c16cbe4e7e7 (diff) | |
download | fork-ledger-ab749742d9ccadc087e412187ee3a9d262aed475.tar.gz fork-ledger-ab749742d9ccadc087e412187ee3a9d262aed475.tar.bz2 fork-ledger-ab749742d9ccadc087e412187ee3a9d262aed475.zip |
Several corrections to transaction finalization
-rw-r--r-- | src/xact.cc | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/xact.cc b/src/xact.cc index eebe4be9..d943e611 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -187,7 +187,7 @@ bool xact_base_t::finalize() post_t * top_post = NULL; foreach (post_t * post, posts) { - if (! post->amount.is_null()) { + if (! post->amount.is_null() && post->must_balance()) { if (post->amount.has_annotation()) top_post = post; else if (! top_post) @@ -220,9 +220,10 @@ bool xact_base_t::finalize() DEBUG("xact.finalize", "primary amount = " << *x); DEBUG("xact.finalize", "secondary amount = " << *y); - commodity_t& comm(x->commodity()); - amount_t per_unit_cost; - amount_t total_cost; + commodity_t& comm(x->commodity()); + amount_t per_unit_cost; + amount_t total_cost; + const amount_t * prev_y = y; foreach (post_t * post, posts) { if (post != top_post && post->must_balance() && @@ -233,9 +234,16 @@ bool xact_base_t::finalize() if (total_cost.is_null()) { total_cost = temp; y = &total_cost; - } else { + } + else if (total_cost.commodity() == temp.commodity()) { total_cost += temp; } + else { + DEBUG("xact.finalize", + "multiple price commodities, aborting price calc"); + y = prev_y; + break; + } DEBUG("xact.finalize", "total_cost = " << total_cost); } } |