enforce balancing for bracketed virtual postings
This commit is contained in:
parent
62d2cb71d0
commit
8eb31bc5e3
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
22
Tests.hs
22
Tests.hs
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user