enforce balancing for bracketed virtual postings

This commit is contained in:
Simon Michael 2009-05-16 23:12:42 +00:00
parent 62d2cb71d0
commit 8eb31bc5e3
3 changed files with 30 additions and 1 deletions

View File

@ -82,7 +82,8 @@ showLedgerTransaction' elide t =
isLedgerTransactionBalanced :: LedgerTransaction -> Bool
isLedgerTransactionBalanced (LedgerTransaction {ltpostings=ps}) =
isReallyZeroMixedAmount $ costOfMixedAmount $ sum $ map pamount $ filter isReal ps
all (isReallyZeroMixedAmount . costOfMixedAmount . sum . map pamount)
[filter isReal ps, filter isBalancedVirtual ps]
-- | Ensure that this entry is balanced, possibly auto-filling a missing
-- amount first. We can auto-fill if there is just one non-virtual

View File

@ -31,5 +31,11 @@ showPosting (Posting s a amt _ ttype) =
isReal :: Posting -> Bool
isReal p = ptype p == RegularPosting
isVirtual :: Posting -> Bool
isVirtual p = ptype p == VirtualPosting
isBalancedVirtual :: Posting -> Bool
isBalancedVirtual p = ptype p == BalancedVirtualPosting
hasAmount :: Posting -> Bool
hasAmount = (/= missingamt) . pamount

View File

@ -524,6 +524,28 @@ tests = [
(LedgerTransaction (parsedate "2009/01/01") False "" "a" ""
[Posting False "b" (Mixed [dollars 0]) "" RegularPosting
] ""))
assertBool "virtual postings don't need to balance"
(isLedgerTransactionBalanced
(LedgerTransaction (parsedate "2009/01/01") False "" "a" ""
[Posting False "b" (Mixed [dollars 1.00]) "" RegularPosting
,Posting False "c" (Mixed [dollars (-1.00)]) "" RegularPosting
,Posting False "d" (Mixed [dollars 100]) "" VirtualPosting
] ""))
assertBool "balanced virtual postings need to balance among themselves"
(not $ isLedgerTransactionBalanced
(LedgerTransaction (parsedate "2009/01/01") False "" "a" ""
[Posting False "b" (Mixed [dollars 1.00]) "" RegularPosting
,Posting False "c" (Mixed [dollars (-1.00)]) "" RegularPosting
,Posting False "d" (Mixed [dollars 100]) "" BalancedVirtualPosting
] ""))
assertBool "balanced virtual postings need to balance among themselves (2)"
(isLedgerTransactionBalanced
(LedgerTransaction (parsedate "2009/01/01") False "" "a" ""
[Posting False "b" (Mixed [dollars 1.00]) "" RegularPosting
,Posting False "c" (Mixed [dollars (-1.00)]) "" RegularPosting
,Posting False "d" (Mixed [dollars 100]) "" BalancedVirtualPosting
,Posting False "e" (Mixed [dollars (-100)]) "" BalancedVirtualPosting
] ""))
,"isSubAccountNameOf" ~: do
"assets" `isSubAccountNameOf` "assets" `is` False