Correctly elide amount sometimes in "print"
This commit is contained in:
parent
60617bfd6e
commit
acb3c57332
2 changed files with 43 additions and 13 deletions
54
src/print.cc
54
src/print.cc
|
|
@ -41,6 +41,36 @@
|
||||||
namespace ledger {
|
namespace ledger {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
bool post_has_simple_amount(const post_t& post)
|
||||||
|
{
|
||||||
|
// Is the amount the result of a computation, i.e., it wasn't
|
||||||
|
// explicit specified by the user?
|
||||||
|
if (post.has_flags(POST_CALCULATED))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Is the amount still empty? This shouldn't be true by this point,
|
||||||
|
// but we check anyway for safety.
|
||||||
|
if (post.amount.is_null())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Is the amount a complex expression. If so, the first 'if' should
|
||||||
|
// have triggered.
|
||||||
|
if (post.amount_expr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Is there a balance assignment? If so, don't elide the amount as
|
||||||
|
// that can change the semantics.
|
||||||
|
if (post.assigned_amount)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Does it have an explicitly specified cost (i.e., one that wasn't
|
||||||
|
// calculated for the user)? If so, don't elide the amount!
|
||||||
|
if (post.cost && ! post.has_flags(POST_COST_CALCULATED))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void print_note(std::ostream& out,
|
void print_note(std::ostream& out,
|
||||||
const string& note,
|
const string& note,
|
||||||
const bool note_on_next_line,
|
const bool note_on_next_line,
|
||||||
|
|
@ -123,9 +153,7 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
std::size_t count = xact.posts.size();
|
std::size_t count = xact.posts.size();
|
||||||
#endif
|
|
||||||
std::size_t index = 0;
|
std::size_t index = 0;
|
||||||
|
|
||||||
foreach (post_t * post, xact.posts) {
|
foreach (post_t * post, xact.posts) {
|
||||||
|
|
@ -178,16 +206,18 @@ namespace {
|
||||||
string amt;
|
string amt;
|
||||||
if (post->amount_expr) {
|
if (post->amount_expr) {
|
||||||
amt = post->amount_expr->text();
|
amt = post->amount_expr->text();
|
||||||
} else
|
}
|
||||||
#if 0
|
else if (count == 2 && index == 2 &&
|
||||||
// jww (2012-02-27): Disabled for now because it's not
|
post_has_simple_amount(*post) &&
|
||||||
// outputted valid transactions in every case
|
post_has_simple_amount(*(*xact.posts.begin())) &&
|
||||||
if (! (count == 2 && index == 2 &&
|
((*xact.posts.begin())->amount.commodity() ==
|
||||||
(*xact.posts.begin())->amount.commodity() ==
|
post->amount.commodity())) {
|
||||||
post->amount.commodity() &&
|
// If there are two postings and they both simple amount, and
|
||||||
! (*xact.posts.begin())->cost && ! post->cost))
|
// they are both of the same commodity, don't bother printing
|
||||||
#endif
|
// the second amount as it's always just an inverse of the
|
||||||
{
|
// first.
|
||||||
|
}
|
||||||
|
else {
|
||||||
int amount_width =
|
int amount_width =
|
||||||
(report.HANDLER(amount_width_).specified ?
|
(report.HANDLER(amount_width_).specified ?
|
||||||
report.HANDLER(amount_width_).value.to_int() : 12);
|
report.HANDLER(amount_width_).value.to_int() : 12);
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,5 @@
|
||||||
test equity assets
|
test equity assets
|
||||||
2007/02/02 Opening Balances
|
2007/02/02 Opening Balances
|
||||||
Assets:Investments:Vanguard:VMMXX 0.350 VMMXX
|
Assets:Investments:Vanguard:VMMXX 0.350 VMMXX
|
||||||
Equity:Opening Balances -0.350 VMMXX
|
Equity:Opening Balances
|
||||||
end test
|
end test
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue