fix bug in eliding of posting amounts
This commit is contained in:
		
							parent
							
								
									e9a2fbd2e8
								
							
						
					
					
						commit
						f40d561273
					
				@ -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)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										29
									
								
								Tests.hs
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user