summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-06-07 08:23:22 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-06-07 08:32:14 -0400
commitc85cf0d810846e6ffc2a45b7283adacc202db30f (patch)
treeb444a914c8551951556a15794a94810d38b62414 /src
parenta4d4f9979486eb82c05bd032e1452c2fd400249f (diff)
downloadfork-ledger-c85cf0d810846e6ffc2a45b7283adacc202db30f.tar.gz
fork-ledger-c85cf0d810846e6ffc2a45b7283adacc202db30f.tar.bz2
fork-ledger-c85cf0d810846e6ffc2a45b7283adacc202db30f.zip
Fixed the way prices and costs are print'd
Diffstat (limited to 'src')
-rw-r--r--src/amount.cc4
-rw-r--r--src/annotate.cc28
-rw-r--r--src/annotate.h6
-rw-r--r--src/commodity.h2
-rw-r--r--src/print.cc16
5 files changed, 28 insertions, 28 deletions
diff --git a/src/amount.cc b/src/amount.cc
index f68917f3..ed8f09d1 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -1216,7 +1216,7 @@ void amount_t::parse_conversion(const string& larger_str,
smaller.commodity().set_larger(larger);
}
-void amount_t::print(std::ostream& _out, const uint_least8_t) const
+void amount_t::print(std::ostream& _out, const uint_least8_t flags) const
{
VERIFY(valid());
@@ -1246,7 +1246,7 @@ void amount_t::print(std::ostream& _out, const uint_least8_t) const
// If there are any annotations associated with this commodity, output them
// now.
- comm.write_annotations(out);
+ comm.write_annotations(out, flags & AMOUNT_PRINT_NO_COMPUTED_ANNOTATIONS);
// Things are output to a string first, so that if anyone has specified a
// width or fill for _out, it will be applied to the entire amount string,
diff --git a/src/annotate.cc b/src/annotate.cc
index feb3b3ca..e1e64ac2 100644
--- a/src/annotate.cc
+++ b/src/annotate.cc
@@ -66,15 +66,6 @@ void annotation_t::parse(std::istream& in)
temp.parse(buf, PARSE_NO_MIGRATE);
DEBUG("commodity.annotations", "Parsed annotation price: " << temp);
-
- // Since this price will maintain its own precision, make sure
- // it is at least as large as the base commodity, since the user
- // may have only specified {$1} or something similar.
-
- if (temp.has_commodity() &&
- temp.precision() > temp.commodity().precision())
- temp = temp.rounded(); // no need to retain individual precision
-
price = temp;
}
else if (c == '[') {
@@ -118,18 +109,22 @@ void annotation_t::parse(std::istream& in)
#endif
}
-void annotation_t::print(std::ostream& out, bool keep_base) const
+void annotation_t::print(std::ostream& out, bool keep_base,
+ bool no_computed_annotations) const
{
- if (price)
+ if (price &&
+ (! no_computed_annotations || ! has_flags(ANNOTATION_PRICE_CALCULATED)))
out << " {"
<< (has_flags(ANNOTATION_PRICE_FIXATED) ? "=" : "")
- << (keep_base ? *price : price->unreduced()).rounded()
+ << (keep_base ? *price : price->unreduced())
<< '}';
- if (date)
+ if (date &&
+ (! no_computed_annotations || ! has_flags(ANNOTATION_DATE_CALCULATED)))
out << " [" << format_date(*date, FMT_WRITTEN) << ']';
- if (tag)
+ if (tag &&
+ (! no_computed_annotations || ! has_flags(ANNOTATION_TAG_CALCULATED)))
out << " (" << *tag << ')';
}
@@ -197,9 +192,10 @@ annotated_commodity_t::strip_annotations(const keep_details_t& what_to_keep)
return *new_comm;
}
-void annotated_commodity_t::write_annotations(std::ostream& out) const
+void annotated_commodity_t::write_annotations
+ (std::ostream& out, bool no_computed_annotations) const
{
- details.print(out, pool().keep_base);
+ details.print(out, pool().keep_base, no_computed_annotations);
}
} // namespace ledger
diff --git a/src/annotate.h b/src/annotate.h
index 6ef26476..4f2f1b04 100644
--- a/src/annotate.h
+++ b/src/annotate.h
@@ -87,7 +87,8 @@ struct annotation_t : public supports_flags<>,
void parse(std::istream& in);
- void print(std::ostream& out, bool keep_base = false) const;
+ void print(std::ostream& out, bool keep_base = false,
+ bool no_computed_annotations = false) const;
bool valid() const {
assert(*this);
@@ -230,7 +231,8 @@ public:
}
virtual commodity_t& strip_annotations(const keep_details_t& what_to_keep);
- virtual void write_annotations(std::ostream& out) const;
+ virtual void write_annotations(std::ostream& out,
+ bool no_computed_annotations = false) const;
#if defined(HAVE_BOOST_SERIALIZATION)
private:
diff --git a/src/commodity.h b/src/commodity.h
index d8aad10d..8fe00a6d 100644
--- a/src/commodity.h
+++ b/src/commodity.h
@@ -273,7 +273,7 @@ public:
virtual commodity_t& strip_annotations(const keep_details_t&) {
return *this;
}
- virtual void write_annotations(std::ostream&) const {}
+ virtual void write_annotations(std::ostream&, bool) const {}
commodity_pool_t& pool() const {
return *parent_;
diff --git a/src/print.cc b/src/print.cc
index 5a72b03e..84aa441f 100644
--- a/src/print.cc
+++ b/src/print.cc
@@ -177,9 +177,9 @@ namespace {
report.HANDLER(amount_width_).value.to_int() : 12);
std::ostringstream amt_str;
- report.scrub(post->amount)
- .print(amt_str, amount_width, -1, AMOUNT_PRINT_RIGHT_JUSTIFY |
- AMOUNT_PRINT_NO_COMPUTED_ANNOTATIONS);
+ value_t(post->amount).print(amt_str, amount_width, -1,
+ AMOUNT_PRINT_RIGHT_JUSTIFY |
+ AMOUNT_PRINT_NO_COMPUTED_ANNOTATIONS);
amt = amt_str.str();
}
@@ -191,15 +191,17 @@ namespace {
amtbuf << string(2 - (slip + amt_slip), ' ');
amtbuf << amt;
- if (post->cost && ! post->has_flags(POST_CALCULATED)) {
+ if (post->cost &&
+ ! post->has_flags(POST_CALCULATED | POST_COST_CALCULATED)) {
if (post->has_flags(POST_COST_IN_FULL))
- amtbuf << " @@ " << report.scrub(post->cost->abs());
+ amtbuf << " @@ " << post->cost->abs();
else
- amtbuf << " @ " << report.scrub((*post->cost / post->amount).abs());
+ amtbuf << " @ "
+ << (*post->cost / post->amount).abs();
}
if (post->assigned_amount)
- amtbuf << " = " << report.scrub(*post->assigned_amount);
+ amtbuf << " = " << post->assigned_amount;
string trailer = amtbuf.str();
out << trailer;