fix reporting of unbalanced entries
This commit is contained in:
		
							parent
							
								
									0f91583230
								
							
						
					
					
						commit
						f69716ddf9
					
				@ -71,15 +71,19 @@ showEntry e =
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
isEntryBalanced :: Entry -> Bool
 | 
					isEntryBalanced :: Entry -> Bool
 | 
				
			||||||
isEntryBalanced (Entry {etransactions=ts}) = 
 | 
					isEntryBalanced (Entry {etransactions=ts}) = 
 | 
				
			||||||
    isZeroMixedAmount $ sum $ map tamount $ filter isReal ts
 | 
					    isZeroMixedAmount $ costOfMixedAmount $ sum $ map tamount $ filter isReal ts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- | Fill in a missing balance in this entry, if we have enough
 | 
					-- | Ensure that this entry is balanced, possibly auto-filling a missing
 | 
				
			||||||
-- information to do that. Excluding virtual transactions, there should be
 | 
					-- amount first. We can auto-fill if there is just one non-virtual
 | 
				
			||||||
-- at most one missing balance. Otherwise, raise an error.
 | 
					-- transaction without an amount. The auto-filled balance will be
 | 
				
			||||||
-- The new balance will be converted to cost basis if possible.
 | 
					-- converted to cost basis if possible. If the entry can not be balanced,
 | 
				
			||||||
 | 
					-- raise an error.
 | 
				
			||||||
balanceEntry :: Entry -> Entry
 | 
					balanceEntry :: Entry -> Entry
 | 
				
			||||||
balanceEntry e@Entry{etransactions=ts} = e{etransactions=ts'}
 | 
					balanceEntry e@Entry{etransactions=ts} = (e{etransactions=ts'})
 | 
				
			||||||
    where
 | 
					    where
 | 
				
			||||||
 | 
					      check e
 | 
				
			||||||
 | 
					          | isEntryBalanced e = e
 | 
				
			||||||
 | 
					          | otherwise = error $ "could not balance this entry:\n" ++ show e
 | 
				
			||||||
      (withamounts, missingamounts) = partition hasAmount $ filter isReal ts
 | 
					      (withamounts, missingamounts) = partition hasAmount $ filter isReal ts
 | 
				
			||||||
      ts' = case (length missingamounts) of
 | 
					      ts' = case (length missingamounts) of
 | 
				
			||||||
              0 -> ts
 | 
					              0 -> ts
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								NOTES
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								NOTES
									
									
									
									
									
								
							@ -10,7 +10,6 @@ clever tricks like the plague." --Edsger Dijkstra
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
* to do
 | 
					* to do
 | 
				
			||||||
** errors
 | 
					** errors
 | 
				
			||||||
*** does not catch an unbalanced entry
 | 
					 | 
				
			||||||
*** can't parse comment line immediately after or within an entry
 | 
					*** can't parse comment line immediately after or within an entry
 | 
				
			||||||
*** depth-limited balance report may not show final total
 | 
					*** depth-limited balance report may not show final total
 | 
				
			||||||
*** print does not always give tidy layout
 | 
					*** print does not always give tidy layout
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user