summaryrefslogtreecommitdiff
path: root/src/xact.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2013-05-19 03:38:14 -0500
committerJohn Wiegley <johnw@newartisans.com>2013-05-19 03:38:20 -0500
commit82345899f76ad35cb979bf8750740d6b9ac8382b (patch)
treed5734274ae6508756228e500c4ee0c3d64197a01 /src/xact.cc
parent2f919000099254c61ceb045514c1630f6dc08011 (diff)
downloadfork-ledger-82345899f76ad35cb979bf8750740d6b9ac8382b.tar.gz
fork-ledger-82345899f76ad35cb979bf8750740d6b9ac8382b.tar.bz2
fork-ledger-82345899f76ad35cb979bf8750740d6b9ac8382b.zip
Remove some unnecessary and complicated logic
Fixes #712
Diffstat (limited to 'src/xact.cc')
-rw-r--r--src/xact.cc39
1 files changed, 5 insertions, 34 deletions
diff --git a/src/xact.cc b/src/xact.cc
index 8aecf5d6..7ea15322 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -252,44 +252,15 @@ bool xact_base_t::finalize()
const amount_t * x = &(*a++).second;
const amount_t * y = &(*a++).second;
- if (x->commodity() != top_post->amount.commodity()) {
- const amount_t * t = x;
- x = y;
- y = t;
- }
-
if (*x && *y) {
+ if (x->commodity() != top_post->amount.commodity())
+ std::swap(x, y);
+
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;
- const amount_t * prev_y = y;
-
- foreach (post_t * post, posts) {
- if (post != top_post && post->must_balance() &&
- ! post->amount.is_null() &&
- post->amount.has_annotation() &&
- post->amount.annotation().price) {
- amount_t temp = *post->amount.annotation().price * post->amount;
- if (total_cost.is_null()) {
- total_cost = temp;
- y = &total_cost;
- }
- 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);
- }
- }
- per_unit_cost = (*y / *x).abs().unrounded();
+ commodity_t& comm(x->commodity());
+ amount_t per_unit_cost = (*y / *x).abs().unrounded();
DEBUG("xact.finalize", "per_unit_cost = " << per_unit_cost);