more balance/amount clarifications and a test
This commit is contained in:
		
							parent
							
								
									9aaf489a38
								
							
						
					
					
						commit
						1273f02a9a
					
				| @ -109,6 +109,7 @@ instance Num MixedAmount where | |||||||
|     negate (Mixed as) = Mixed $ map negateAmountPreservingPrice as |     negate (Mixed as) = Mixed $ map negateAmountPreservingPrice as | ||||||
|         where negateAmountPreservingPrice a = (-a){price=price a} |         where negateAmountPreservingPrice a = (-a){price=price a} | ||||||
|     (+) (Mixed as) (Mixed bs) = normaliseMixedAmount $ Mixed $ as ++ bs |     (+) (Mixed as) (Mixed bs) = normaliseMixedAmount $ Mixed $ as ++ bs | ||||||
|  |     -- (+) (Mixed as) (Mixed bs) = normaliseMixedAmountPreservingHighestPrecision $ Mixed $ as ++ bs | ||||||
|     (*)    = error' "programming error, mixed amounts do not support multiplication" |     (*)    = error' "programming error, mixed amounts do not support multiplication" | ||||||
|     abs    = error' "programming error, mixed amounts do not support abs" |     abs    = error' "programming error, mixed amounts do not support abs" | ||||||
|     signum = error' "programming error, mixed amounts do not support signum" |     signum = error' "programming error, mixed amounts do not support signum" | ||||||
|  | |||||||
| @ -415,6 +415,10 @@ postingsByAccount ps = m' | |||||||
|       groupedps = groupBy (\p1 p2 -> paccount p1 == paccount p2) sortedps |       groupedps = groupBy (\p1 p2 -> paccount p1 == paccount p2) sortedps | ||||||
|       m' = Map.fromList [(paccount $ head g, g) | g <- groupedps] |       m' = Map.fromList [(paccount $ head g, g) | g <- groupedps] | ||||||
| 
 | 
 | ||||||
|  | -- debug helpers | ||||||
|  | traceAmountPrecision a = trace (show $ map (precision . commodity) $ amounts a) a | ||||||
|  | tracePostingsCommodities ps = trace (show $ map ((map (precision . commodity) . amounts) . pamount) ps) ps | ||||||
|  | 
 | ||||||
| tests_Hledger_Data_Journal = TestList [ | tests_Hledger_Data_Journal = TestList [ | ||||||
|  ] |  ] | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -17,7 +17,7 @@ import Hledger.Data.Types | |||||||
| import Hledger.Utils | import Hledger.Utils | ||||||
| import Hledger.Data.Posting | import Hledger.Data.Posting | ||||||
| import Hledger.Data.Dates (getCurrentYear) | import Hledger.Data.Dates (getCurrentYear) | ||||||
| import Hledger.Data.Journal (nullctx, nulljournal, journalFinalise) | import Hledger.Data.Journal | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| juSequence :: [JournalUpdate] -> JournalUpdate | juSequence :: [JournalUpdate] -> JournalUpdate | ||||||
|  | |||||||
| @ -153,32 +153,30 @@ accountsReportItemAsText opts format (_, accountName, depth, Mixed amounts) = | |||||||
|     case amounts of |     case amounts of | ||||||
|       [] -> [] |       [] -> [] | ||||||
|       [a] -> [formatAccountsReportItem opts (Just accountName) depth a format] |       [a] -> [formatAccountsReportItem opts (Just accountName) depth a format] | ||||||
|       (as) -> asText as |       (as) -> multiline as | ||||||
|     where |     where | ||||||
|       asText :: [Amount] -> [String] |       multiline :: [Amount] -> [String] | ||||||
|       asText []     = [] |       multiline []     = [] | ||||||
|       asText [a]    = [formatAccountsReportItem opts (Just accountName) depth a format] |       multiline [a]    = [formatAccountsReportItem opts (Just accountName) depth a format] | ||||||
|       asText (a:as) = (formatAccountsReportItem opts Nothing depth a format) : asText as |       multiline (a:as) = (formatAccountsReportItem opts Nothing depth a format) : multiline as | ||||||
| 
 | 
 | ||||||
| formatAccountsReportItem :: ReportOpts -> Maybe AccountName -> Int -> Amount -> [FormatString] -> String | formatAccountsReportItem :: ReportOpts -> Maybe AccountName -> Int -> Amount -> [FormatString] -> String | ||||||
| formatAccountsReportItem _ _ _ _ [] = "" | formatAccountsReportItem _ _ _ _ [] = "" | ||||||
| formatAccountsReportItem opts accountName depth amount (fmt:fmts) = | formatAccountsReportItem opts accountName depth amount (fmt:fmts) = | ||||||
|   s ++ (formatAccountsReportItem opts accountName depth amount fs) |   s ++ (formatAccountsReportItem opts accountName depth amount fmts) | ||||||
|   where |   where | ||||||
|     s = case fmt of |     s = case fmt of | ||||||
|          FormatLiteral l -> l |          FormatLiteral l -> l | ||||||
|          FormatField ljust min max field  -> formatField opts accountName depth amount ljust min max field |          FormatField ljust min max field  -> formatField opts accountName depth amount ljust min max field | ||||||
| 
 | 
 | ||||||
| formatField :: ReportOpts -> Maybe AccountName -> Int -> Amount -> Bool -> Maybe Int -> Maybe Int -> Field -> String | formatField :: ReportOpts -> Maybe AccountName -> Int -> Amount -> Bool -> Maybe Int -> Maybe Int -> Field -> String | ||||||
| formatField opts accountName depth balance ljust min max field = case field of | formatField opts accountName depth total ljust min max field = case field of | ||||||
|         Format.Account     -> formatValue ljust min max a |         Format.Account     -> formatValue ljust min max $ maybe "" (accountNameDrop (drop_ opts)) accountName | ||||||
|         Format.DepthSpacer -> case min of |         Format.DepthSpacer -> case min of | ||||||
|                                Just m  -> formatValue ljust Nothing max $ replicate (depth * m) ' ' |                                Just m  -> formatValue ljust Nothing max $ replicate (depth * m) ' ' | ||||||
|                                Nothing -> formatValue ljust Nothing max $ replicate depth ' ' |                                Nothing -> formatValue ljust Nothing max $ replicate depth ' ' | ||||||
|         Format.Total       -> formatValue ljust min max $ showAmountWithoutPrice balance |         Format.Total       -> formatValue ljust min max $ showAmountWithoutPrice total | ||||||
|         _                  -> "" |         _                  -> "" | ||||||
|     where |  | ||||||
|       a = maybe "" (accountNameDrop (drop_ opts)) accountName |  | ||||||
| 
 | 
 | ||||||
| tests_Hledger_Cli_Balance = TestList | tests_Hledger_Cli_Balance = TestList | ||||||
|  [ |  [ | ||||||
|  | |||||||
							
								
								
									
										12
									
								
								tests/balance-precision.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								tests/balance-precision.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | # | ||||||
|  | bin/hledger -f- bal | ||||||
|  | <<< | ||||||
|  | 1/1 | ||||||
|  |   a   1.00 | ||||||
|  |   b  -1 | ||||||
|  | >>> | ||||||
|  |                 1.00  a | ||||||
|  |                -1.00  b | ||||||
|  | -------------------- | ||||||
|  |                    0 | ||||||
|  | >>>=0 | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user