diff --git a/Ledger/LedgerTransaction.hs b/Ledger/LedgerTransaction.hs index 8d2261f23..d607806bb 100644 --- a/Ledger/LedgerTransaction.hs +++ b/Ledger/LedgerTransaction.hs @@ -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) diff --git a/Tests.hs b/Tests.hs index 6840f8b49..0fa9bca67 100644 --- a/Tests.hs +++ b/Tests.hs @@ -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" ,"" ]