fix bug in eliding of posting amounts

This commit is contained in:
Simon Michael 2009-04-07 23:58:04 +00:00
parent e9a2fbd2e8
commit f40d561273
2 changed files with 31 additions and 7 deletions

View File

@ -67,7 +67,8 @@ showLedgerTransaction' elide t =
comment = if (length $ ltcomment t) > 0 then " ; "++(ltcomment t) else ""
showdate d = printf "%-10s" (showDate d)
showpostings ps
| elide && length ps == 2 = [showposting (ps !! 0), showpostingnoamt (ps !! 1)]
| elide && length ps > 1 && isLedgerTransactionBalanced t
= map showposting (init ps) ++ [showpostingnoamt (last ps)]
| otherwise = map showposting ps
where
showposting p = showacct p ++ " " ++ (showamount $ pamount p) ++ (showcomment $ pcomment p)

View File

@ -604,7 +604,7 @@ tests = [
["2008/06/03 * eat & shop"
," expenses:food $1"
," expenses:supplies $1"
," assets:cash $-2"
," assets:cash"
,""
]
@ -621,7 +621,7 @@ tests = [
,"2008/06/03 * eat & shop"
," expenses:food $1"
," expenses:supplies $1"
," assets:cash $-2"
," assets:cash"
,""
,"2008/12/31 * pay off"
," liabilities:debts $1"
@ -762,7 +762,30 @@ tests = [
,"show hours" ~: show (hours 1) ~?= "1.0h"
,"showLedgerTransaction" ~: do
showLedgerTransaction entry1 `is` entry1_str
assertEqual "show a balanced transaction, eliding last amount"
(unlines
["2007/01/28 coopportunity"
," expenses:food:groceries $47.18"
," assets:checking"
,""
])
(showLedgerTransaction
(LedgerTransaction (parsedate "2007/01/28") False "" "coopportunity" ""
[Posting False "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularPosting
,Posting False "assets:checking" (Mixed [dollars (-47.18)]) "" RegularPosting
] ""))
assertEqual "show an unbalanced transaction, should not elide"
(unlines
["2007/01/28 coopportunity"
," expenses:food:groceries $47.18"
," assets:checking $-47.19"
,""
])
(showLedgerTransaction
(LedgerTransaction (parsedate "2007/01/28") False "" "coopportunity" ""
[Posting False "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularPosting
,Posting False "assets:checking" (Mixed [dollars (-47.19)]) "" RegularPosting
] ""))
,"unicode in balance layout" ~: do
l <- ledgerFromStringWithOpts [] [] sampletime
@ -958,9 +981,9 @@ entry1 =
entry2_str = unlines
["2007/01/27 * joes diner"
," expenses:food:dining $10.00"
," expenses:gifts $10.00"
," assets:checking $-20.00"
," expenses:food:dining $10.00"
," expenses:gifts $10.00"
," assets:checking $-20.00"
,""
]