refactor: clean up Posting construction
This commit is contained in:
parent
26ad56e1b2
commit
4aafeb32e6
@ -524,26 +524,10 @@ Right samplejournal = journalBalanceTransactions $
|
|||||||
tdescription="income",
|
tdescription="income",
|
||||||
tcomment="",
|
tcomment="",
|
||||||
ttags=[],
|
ttags=[],
|
||||||
tpostings=[
|
tpostings=
|
||||||
Posting {
|
["assets:bank:checking" `post` usd 1
|
||||||
pstatus=False,
|
,"income:salary" `post` missingamt
|
||||||
paccount="assets:bank:checking",
|
],
|
||||||
pamount=(Mixed [usd 1]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount="income:salary",
|
|
||||||
pamount=(missingmixedamt),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tpreceding_comment_lines=""
|
tpreceding_comment_lines=""
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
@ -555,26 +539,10 @@ Right samplejournal = journalBalanceTransactions $
|
|||||||
tdescription="gift",
|
tdescription="gift",
|
||||||
tcomment="",
|
tcomment="",
|
||||||
ttags=[],
|
ttags=[],
|
||||||
tpostings=[
|
tpostings=
|
||||||
Posting {
|
["assets:bank:checking" `post` usd 1
|
||||||
pstatus=False,
|
,"income:gifts" `post` missingamt
|
||||||
paccount="assets:bank:checking",
|
],
|
||||||
pamount=(Mixed [usd 1]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount="income:gifts",
|
|
||||||
pamount=(missingmixedamt),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tpreceding_comment_lines=""
|
tpreceding_comment_lines=""
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
@ -586,26 +554,10 @@ Right samplejournal = journalBalanceTransactions $
|
|||||||
tdescription="save",
|
tdescription="save",
|
||||||
tcomment="",
|
tcomment="",
|
||||||
ttags=[],
|
ttags=[],
|
||||||
tpostings=[
|
tpostings=
|
||||||
Posting {
|
["assets:bank:saving" `post` usd 1
|
||||||
pstatus=False,
|
,"assets:bank:checking" `post` usd (-1)
|
||||||
paccount="assets:bank:saving",
|
],
|
||||||
pamount=(Mixed [usd 1]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount="assets:bank:checking",
|
|
||||||
pamount=(Mixed [usd (-1)]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tpreceding_comment_lines=""
|
tpreceding_comment_lines=""
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
@ -617,35 +569,10 @@ Right samplejournal = journalBalanceTransactions $
|
|||||||
tdescription="eat & shop",
|
tdescription="eat & shop",
|
||||||
tcomment="",
|
tcomment="",
|
||||||
ttags=[],
|
ttags=[],
|
||||||
tpostings=[
|
tpostings=["expenses:food" `post` usd 1
|
||||||
Posting {
|
,"expenses:supplies" `post` usd 1
|
||||||
pstatus=False,
|
,"assets:cash" `post` missingamt
|
||||||
paccount="expenses:food",
|
],
|
||||||
pamount=(Mixed [usd 1]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount="expenses:supplies",
|
|
||||||
pamount=(Mixed [usd 1]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount="assets:cash",
|
|
||||||
pamount=(missingmixedamt),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tpreceding_comment_lines=""
|
tpreceding_comment_lines=""
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
@ -657,26 +584,9 @@ Right samplejournal = journalBalanceTransactions $
|
|||||||
tdescription="pay off",
|
tdescription="pay off",
|
||||||
tcomment="",
|
tcomment="",
|
||||||
ttags=[],
|
ttags=[],
|
||||||
tpostings=[
|
tpostings=["liabilities:debts" `post` usd 1
|
||||||
Posting {
|
,"assets:bank:checking" `post` usd (-1)
|
||||||
pstatus=False,
|
],
|
||||||
paccount="liabilities:debts",
|
|
||||||
pamount=(Mixed [usd 1]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount="assets:bank:checking",
|
|
||||||
pamount=(Mixed [usd (-1)]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tpreceding_comment_lines=""
|
tpreceding_comment_lines=""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -10,6 +10,8 @@ look up the date or description there.
|
|||||||
module Hledger.Data.Posting (
|
module Hledger.Data.Posting (
|
||||||
-- * Posting
|
-- * Posting
|
||||||
nullposting,
|
nullposting,
|
||||||
|
posting,
|
||||||
|
post,
|
||||||
-- * operations
|
-- * operations
|
||||||
postingCleared,
|
postingCleared,
|
||||||
isReal,
|
isReal,
|
||||||
@ -44,6 +46,7 @@ module Hledger.Data.Posting (
|
|||||||
)
|
)
|
||||||
where
|
where
|
||||||
import Data.List
|
import Data.List
|
||||||
|
import Data.Maybe
|
||||||
import Data.Ord
|
import Data.Ord
|
||||||
import Data.Time.Calendar
|
import Data.Time.Calendar
|
||||||
import Safe
|
import Safe
|
||||||
@ -59,8 +62,20 @@ import Hledger.Data.Dates (nulldate, spanContainsDate)
|
|||||||
|
|
||||||
instance Show Posting where show = showPosting
|
instance Show Posting where show = showPosting
|
||||||
|
|
||||||
nullposting :: Posting
|
nullposting, posting :: Posting
|
||||||
nullposting = Posting False "" nullmixedamt "" RegularPosting [] Nothing
|
nullposting = Posting
|
||||||
|
{pstatus=False
|
||||||
|
,paccount=""
|
||||||
|
,pamount=nullmixedamt
|
||||||
|
,pcomment=""
|
||||||
|
,ptype=RegularPosting
|
||||||
|
,ptags=[]
|
||||||
|
,ptransaction=Nothing
|
||||||
|
}
|
||||||
|
posting = nullposting
|
||||||
|
|
||||||
|
post :: AccountName -> Amount -> Posting
|
||||||
|
post acct amt = posting {paccount=acct, pamount=mixed amt}
|
||||||
|
|
||||||
showPosting :: Posting -> String
|
showPosting :: Posting -> String
|
||||||
showPosting p@Posting{paccount=a,pamount=amt,ptype=t} =
|
showPosting p@Posting{paccount=a,pamount=amt,ptype=t} =
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import Hledger.Utils
|
|||||||
import Hledger.Data.Types
|
import Hledger.Data.Types
|
||||||
import Hledger.Data.Dates
|
import Hledger.Data.Dates
|
||||||
import Hledger.Data.Amount
|
import Hledger.Data.Amount
|
||||||
|
import Hledger.Data.Posting
|
||||||
import Hledger.Data.Transaction
|
import Hledger.Data.Transaction
|
||||||
|
|
||||||
instance Show TimeLogEntry where
|
instance Show TimeLogEntry where
|
||||||
@ -94,8 +95,8 @@ entryFromTimeLogInOut i o
|
|||||||
idate = localDay itime
|
idate = localDay itime
|
||||||
hours = elapsedSeconds (toutc otime) (toutc itime) / 3600 where toutc = localTimeToUTC utc
|
hours = elapsedSeconds (toutc otime) (toutc itime) / 3600 where toutc = localTimeToUTC utc
|
||||||
amount = Mixed [hrs hours]
|
amount = Mixed [hrs hours]
|
||||||
ps = [Posting{pstatus=False,paccount=acctname,pamount=amount,
|
ps = [posting{paccount=acctname, pamount=amount, ptype=VirtualPosting, ptransaction=Just t}]
|
||||||
pcomment="",ptype=VirtualPosting,ptags=[],ptransaction=Just t}]
|
|
||||||
|
|
||||||
tests_Hledger_Data_TimeLog = TestList [
|
tests_Hledger_Data_TimeLog = TestList [
|
||||||
|
|
||||||
|
|||||||
@ -376,8 +376,8 @@ tests_Hledger_Data_Transaction = TestList $ concat [
|
|||||||
,""
|
,""
|
||||||
])
|
])
|
||||||
(let t = Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" "" []
|
(let t = Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" "" []
|
||||||
[Posting False "expenses:food:groceries" (Mixed [usd 47.18]) "" RegularPosting [] (Just t)
|
[posting{paccount="expenses:food:groceries", pamount=Mixed [usd 47.18], ptransaction=Just t}
|
||||||
,Posting False "assets:checking" (Mixed [usd (-47.18)]) "" RegularPosting [] (Just t)
|
,posting{paccount="assets:checking", pamount=Mixed [usd (-47.18)], ptransaction=Just t}
|
||||||
] ""
|
] ""
|
||||||
in showTransaction t)
|
in showTransaction t)
|
||||||
|
|
||||||
@ -390,8 +390,8 @@ tests_Hledger_Data_Transaction = TestList $ concat [
|
|||||||
,""
|
,""
|
||||||
])
|
])
|
||||||
(let t = Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" "" []
|
(let t = Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" "" []
|
||||||
[Posting False "expenses:food:groceries" (Mixed [usd 47.18]) "" RegularPosting [] (Just t)
|
[posting{paccount="expenses:food:groceries", pamount=Mixed [usd 47.18], ptransaction=Just t}
|
||||||
,Posting False "assets:checking" (Mixed [usd (-47.18)]) "" RegularPosting [] (Just t)
|
,posting{paccount="assets:checking", pamount=Mixed [usd (-47.18)], ptransaction=Just t}
|
||||||
] ""
|
] ""
|
||||||
in showTransactionUnelided t)
|
in showTransactionUnelided t)
|
||||||
|
|
||||||
@ -406,8 +406,8 @@ tests_Hledger_Data_Transaction = TestList $ concat [
|
|||||||
])
|
])
|
||||||
(showTransaction
|
(showTransaction
|
||||||
(txnTieKnot $ Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" "" []
|
(txnTieKnot $ Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" "" []
|
||||||
[Posting False "expenses:food:groceries" (Mixed [usd 47.18]) "" RegularPosting [] Nothing
|
[posting{paccount="expenses:food:groceries", pamount=Mixed [usd 47.18]}
|
||||||
,Posting False "assets:checking" (Mixed [usd (-47.19)]) "" RegularPosting [] Nothing
|
,posting{paccount="assets:checking", pamount=Mixed [usd (-47.19)]}
|
||||||
] ""))
|
] ""))
|
||||||
|
|
||||||
,"showTransaction" ~: do
|
,"showTransaction" ~: do
|
||||||
@ -419,7 +419,7 @@ tests_Hledger_Data_Transaction = TestList $ concat [
|
|||||||
])
|
])
|
||||||
(showTransaction
|
(showTransaction
|
||||||
(txnTieKnot $ Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" "" []
|
(txnTieKnot $ Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" "" []
|
||||||
[Posting False "expenses:food:groceries" (Mixed [usd 47.18]) "" RegularPosting [] Nothing
|
[posting{paccount="expenses:food:groceries", pamount=Mixed [usd 47.18]}
|
||||||
] ""))
|
] ""))
|
||||||
|
|
||||||
,"showTransaction" ~: do
|
,"showTransaction" ~: do
|
||||||
@ -431,7 +431,7 @@ tests_Hledger_Data_Transaction = TestList $ concat [
|
|||||||
])
|
])
|
||||||
(showTransaction
|
(showTransaction
|
||||||
(txnTieKnot $ Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" "" []
|
(txnTieKnot $ Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" "" []
|
||||||
[Posting False "expenses:food:groceries" missingmixedamt "" RegularPosting [] Nothing
|
[posting{paccount="expenses:food:groceries", pamount=missingmixedamt}
|
||||||
] ""))
|
] ""))
|
||||||
|
|
||||||
,"showTransaction" ~: do
|
,"showTransaction" ~: do
|
||||||
@ -444,28 +444,28 @@ tests_Hledger_Data_Transaction = TestList $ concat [
|
|||||||
])
|
])
|
||||||
(showTransaction
|
(showTransaction
|
||||||
(txnTieKnot $ Transaction (parsedate "2010/01/01") Nothing False "" "x" "" []
|
(txnTieKnot $ Transaction (parsedate "2010/01/01") Nothing False "" "x" "" []
|
||||||
[Posting False "a" (Mixed [num 1 `at` (usd 2 `withPrecision` 0)]) "" RegularPosting [] Nothing
|
[posting{paccount="a", pamount=Mixed [num 1 `at` (usd 2 `withPrecision` 0)]}
|
||||||
,Posting False "b" missingmixedamt "" RegularPosting [] Nothing
|
,posting{paccount="b", pamount= missingmixedamt}
|
||||||
] ""))
|
] ""))
|
||||||
|
|
||||||
,"balanceTransaction" ~: do
|
,"balanceTransaction" ~: do
|
||||||
assertBool "detect unbalanced entry, sign error"
|
assertBool "detect unbalanced entry, sign error"
|
||||||
(isLeft $ balanceTransaction Nothing
|
(isLeft $ balanceTransaction Nothing
|
||||||
(Transaction (parsedate "2007/01/28") Nothing False "" "test" "" []
|
(Transaction (parsedate "2007/01/28") Nothing False "" "test" "" []
|
||||||
[Posting False "a" (Mixed [usd 1]) "" RegularPosting [] Nothing,
|
[posting{paccount="a", pamount=Mixed [usd 1]}
|
||||||
Posting False "b" (Mixed [usd 1]) "" RegularPosting [] Nothing
|
,posting{paccount="b", pamount=Mixed [usd 1]}
|
||||||
] ""))
|
] ""))
|
||||||
|
|
||||||
assertBool "detect unbalanced entry, multiple missing amounts"
|
assertBool "detect unbalanced entry, multiple missing amounts"
|
||||||
(isLeft $ balanceTransaction Nothing
|
(isLeft $ balanceTransaction Nothing
|
||||||
(Transaction (parsedate "2007/01/28") Nothing False "" "test" "" []
|
(Transaction (parsedate "2007/01/28") Nothing False "" "test" "" []
|
||||||
[Posting False "a" missingmixedamt "" RegularPosting [] Nothing,
|
[posting{paccount="a", pamount=missingmixedamt}
|
||||||
Posting False "b" missingmixedamt "" RegularPosting [] Nothing
|
,posting{paccount="b", pamount=missingmixedamt}
|
||||||
] ""))
|
] ""))
|
||||||
|
|
||||||
let e = balanceTransaction Nothing (Transaction (parsedate "2007/01/28") Nothing False "" "" "" []
|
let e = balanceTransaction Nothing (Transaction (parsedate "2007/01/28") Nothing False "" "" "" []
|
||||||
[Posting False "a" (Mixed [usd 1]) "" RegularPosting [] Nothing,
|
[posting{paccount="a", pamount=Mixed [usd 1]}
|
||||||
Posting False "b" missingmixedamt "" RegularPosting [] Nothing
|
,posting{paccount="b", pamount=missingmixedamt}
|
||||||
] "")
|
] "")
|
||||||
assertBool "balanceTransaction allows one missing amount" (isRight e)
|
assertBool "balanceTransaction allows one missing amount" (isRight e)
|
||||||
assertEqual "balancing amount is inferred"
|
assertEqual "balancing amount is inferred"
|
||||||
@ -475,8 +475,8 @@ tests_Hledger_Data_Transaction = TestList $ concat [
|
|||||||
Left _ -> error' "should not happen")
|
Left _ -> error' "should not happen")
|
||||||
|
|
||||||
let e = balanceTransaction Nothing (Transaction (parsedate "2011/01/01") Nothing False "" "" "" []
|
let e = balanceTransaction Nothing (Transaction (parsedate "2011/01/01") Nothing False "" "" "" []
|
||||||
[Posting False "a" (Mixed [usd 1.35]) "" RegularPosting [] Nothing,
|
[posting{paccount="a", pamount=Mixed [usd 1.35]}
|
||||||
Posting False "b" (Mixed [eur (-1)]) "" RegularPosting [] Nothing
|
,posting{paccount="b", pamount=Mixed [eur (-1)]}
|
||||||
] "")
|
] "")
|
||||||
assertBool "balanceTransaction can infer conversion price" (isRight e)
|
assertBool "balanceTransaction can infer conversion price" (isRight e)
|
||||||
assertEqual "balancing conversion price is inferred"
|
assertEqual "balancing conversion price is inferred"
|
||||||
@ -487,52 +487,52 @@ tests_Hledger_Data_Transaction = TestList $ concat [
|
|||||||
|
|
||||||
assertBool "balanceTransaction balances based on cost if there are unit prices" (isRight $
|
assertBool "balanceTransaction balances based on cost if there are unit prices" (isRight $
|
||||||
balanceTransaction Nothing (Transaction (parsedate "2011/01/01") Nothing False "" "" "" []
|
balanceTransaction Nothing (Transaction (parsedate "2011/01/01") Nothing False "" "" "" []
|
||||||
[Posting False "a" (Mixed [usd 1 `at` eur 2]) "" RegularPosting [] Nothing
|
[posting{paccount="a", pamount=Mixed [usd 1 `at` eur 2]}
|
||||||
,Posting False "a" (Mixed [usd (-2) `at` eur 1]) "" RegularPosting [] Nothing
|
,posting{paccount="a", pamount=Mixed [usd (-2) `at` eur 1]}
|
||||||
] ""))
|
] ""))
|
||||||
|
|
||||||
assertBool "balanceTransaction balances based on cost if there are total prices" (isRight $
|
assertBool "balanceTransaction balances based on cost if there are total prices" (isRight $
|
||||||
balanceTransaction Nothing (Transaction (parsedate "2011/01/01") Nothing False "" "" "" []
|
balanceTransaction Nothing (Transaction (parsedate "2011/01/01") Nothing False "" "" "" []
|
||||||
[Posting False "a" (Mixed [usd 1 @@ eur 1]) "" RegularPosting [] Nothing
|
[posting{paccount="a", pamount=Mixed [usd 1 @@ eur 1]}
|
||||||
,Posting False "a" (Mixed [usd (-2) @@ eur 1]) "" RegularPosting [] Nothing
|
,posting{paccount="a", pamount=Mixed [usd (-2) @@ eur 1]}
|
||||||
] ""))
|
] ""))
|
||||||
|
|
||||||
,"isTransactionBalanced" ~: do
|
,"isTransactionBalanced" ~: do
|
||||||
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
||||||
[Posting False "b" (Mixed [usd 1.00]) "" RegularPosting [] (Just t)
|
[posting{paccount="b", pamount=Mixed [usd 1.00], ptransaction=Just t}
|
||||||
,Posting False "c" (Mixed [usd (-1.00)]) "" RegularPosting [] (Just t)
|
,posting{paccount="c", pamount=Mixed [usd (-1.00)], ptransaction=Just t}
|
||||||
] ""
|
] ""
|
||||||
assertBool "detect balanced" (isTransactionBalanced Nothing t)
|
assertBool "detect balanced" (isTransactionBalanced Nothing t)
|
||||||
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
||||||
[Posting False "b" (Mixed [usd 1.00]) "" RegularPosting [] (Just t)
|
[posting{paccount="b", pamount=Mixed [usd 1.00], ptransaction=Just t}
|
||||||
,Posting False "c" (Mixed [usd (-1.01)]) "" RegularPosting [] (Just t)
|
,posting{paccount="c", pamount=Mixed [usd (-1.01)], ptransaction=Just t}
|
||||||
] ""
|
] ""
|
||||||
assertBool "detect unbalanced" (not $ isTransactionBalanced Nothing t)
|
assertBool "detect unbalanced" (not $ isTransactionBalanced Nothing t)
|
||||||
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
||||||
[Posting False "b" (Mixed [usd 1.00]) "" RegularPosting [] (Just t)
|
[posting{paccount="b", pamount=Mixed [usd 1.00], ptransaction=Just t}
|
||||||
] ""
|
] ""
|
||||||
assertBool "detect unbalanced, one posting" (not $ isTransactionBalanced Nothing t)
|
assertBool "detect unbalanced, one posting" (not $ isTransactionBalanced Nothing t)
|
||||||
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
||||||
[Posting False "b" (Mixed [usd 0]) "" RegularPosting [] (Just t)
|
[posting{paccount="b", pamount=Mixed [usd 0], ptransaction=Just t}
|
||||||
] ""
|
] ""
|
||||||
assertBool "one zero posting is considered balanced for now" (isTransactionBalanced Nothing t)
|
assertBool "one zero posting is considered balanced for now" (isTransactionBalanced Nothing t)
|
||||||
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
||||||
[Posting False "b" (Mixed [usd 1.00]) "" RegularPosting [] (Just t)
|
[posting{paccount="b", pamount=Mixed [usd 1.00], ptransaction=Just t}
|
||||||
,Posting False "c" (Mixed [usd (-1.00)]) "" RegularPosting [] (Just t)
|
,posting{paccount="c", pamount=Mixed [usd (-1.00)], ptransaction=Just t}
|
||||||
,Posting False "d" (Mixed [usd 100]) "" VirtualPosting [] (Just t)
|
,posting{paccount="d", pamount=Mixed [usd 100], ptype=VirtualPosting, ptransaction=Just t}
|
||||||
] ""
|
] ""
|
||||||
assertBool "virtual postings don't need to balance" (isTransactionBalanced Nothing t)
|
assertBool "virtual postings don't need to balance" (isTransactionBalanced Nothing t)
|
||||||
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
||||||
[Posting False "b" (Mixed [usd 1.00]) "" RegularPosting [] (Just t)
|
[posting{paccount="b", pamount=Mixed [usd 1.00], ptransaction=Just t}
|
||||||
,Posting False "c" (Mixed [usd (-1.00)]) "" RegularPosting [] (Just t)
|
,posting{paccount="c", pamount=Mixed [usd (-1.00)], ptransaction=Just t}
|
||||||
,Posting False "d" (Mixed [usd 100]) "" BalancedVirtualPosting [] (Just t)
|
,posting{paccount="d", pamount=Mixed [usd 100], ptype=BalancedVirtualPosting, ptransaction=Just t}
|
||||||
] ""
|
] ""
|
||||||
assertBool "balanced virtual postings need to balance among themselves" (not $ isTransactionBalanced Nothing t)
|
assertBool "balanced virtual postings need to balance among themselves" (not $ isTransactionBalanced Nothing t)
|
||||||
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
let t = Transaction (parsedate "2009/01/01") Nothing False "" "a" "" []
|
||||||
[Posting False "b" (Mixed [usd 1.00]) "" RegularPosting [] (Just t)
|
[posting{paccount="b", pamount=Mixed [usd 1.00], ptransaction=Just t}
|
||||||
,Posting False "c" (Mixed [usd (-1.00)]) "" RegularPosting [] (Just t)
|
,posting{paccount="c", pamount=Mixed [usd (-1.00)], ptransaction=Just t}
|
||||||
,Posting False "d" (Mixed [usd 100]) "" BalancedVirtualPosting [] (Just t)
|
,posting{paccount="d", pamount=Mixed [usd 100], ptype=BalancedVirtualPosting, ptransaction=Just t}
|
||||||
,Posting False "e" (Mixed [usd (-100)]) "" BalancedVirtualPosting [] (Just t)
|
,posting{paccount="3", pamount=Mixed [usd (-100)], ptype=BalancedVirtualPosting, ptransaction=Just t}
|
||||||
] ""
|
] ""
|
||||||
assertBool "balanced virtual postings need to balance among themselves (2)" (isTransactionBalanced Nothing t)
|
assertBool "balanced virtual postings need to balance among themselves (2)" (isTransactionBalanced Nothing t)
|
||||||
|
|
||||||
|
|||||||
@ -456,25 +456,9 @@ transactionFromCsvRecord rules fields =
|
|||||||
tcomment=comment,
|
tcomment=comment,
|
||||||
tpreceding_comment_lines=precomment,
|
tpreceding_comment_lines=precomment,
|
||||||
ttags=[],
|
ttags=[],
|
||||||
tpostings=[
|
tpostings=
|
||||||
Posting {
|
[posting {paccount=acct, pamount=a, ptransaction=Just t}
|
||||||
pstatus=False,
|
,posting {paccount=baseacc, pamount=(-baseamount), ptransaction=Just t}
|
||||||
paccount=acct,
|
|
||||||
pamount=a,
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Just t
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount=baseacc,
|
|
||||||
pamount=(-baseamount),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Just t
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
in t
|
in t
|
||||||
|
|||||||
@ -969,26 +969,10 @@ Right samplejournal2 = journalBalanceTransactions $
|
|||||||
tdescription="income",
|
tdescription="income",
|
||||||
tcomment="",
|
tcomment="",
|
||||||
ttags=[],
|
ttags=[],
|
||||||
tpostings=[
|
tpostings=
|
||||||
Posting {
|
[posting {paccount="assets:bank:checking", pamount=Mixed [usd 1]}
|
||||||
pstatus=False,
|
,posting {paccount="income:salary", pamount=missingmixedamt}
|
||||||
paccount="assets:bank:checking",
|
],
|
||||||
pamount=(Mixed [usd 1]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount="income:salary",
|
|
||||||
pamount=(missingmixedamt),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tpreceding_comment_lines=""
|
tpreceding_comment_lines=""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -342,26 +342,10 @@ journal7 = nulljournal {jtxns =
|
|||||||
tdescription="opening balance",
|
tdescription="opening balance",
|
||||||
tcomment="",
|
tcomment="",
|
||||||
ttags=[],
|
ttags=[],
|
||||||
tpostings=[
|
tpostings=
|
||||||
Posting {
|
["assets:cash" `post` usd 4.82
|
||||||
pstatus=False,
|
,"equity:opening balances" `post` usd (-4.82)
|
||||||
paccount="assets:cash",
|
],
|
||||||
pamount=(Mixed [usd 4.82]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount="equity:opening balances",
|
|
||||||
pamount=(Mixed [usd (-4.82)]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tpreceding_comment_lines=""
|
tpreceding_comment_lines=""
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
@ -373,26 +357,10 @@ journal7 = nulljournal {jtxns =
|
|||||||
tdescription="ayres suites",
|
tdescription="ayres suites",
|
||||||
tcomment="",
|
tcomment="",
|
||||||
ttags=[],
|
ttags=[],
|
||||||
tpostings=[
|
tpostings=
|
||||||
Posting {
|
["expenses:vacation" `post` usd 179.92
|
||||||
pstatus=False,
|
,"assets:checking" `post` usd (-179.92)
|
||||||
paccount="expenses:vacation",
|
],
|
||||||
pamount=(Mixed [usd 179.92]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount="assets:checking",
|
|
||||||
pamount=(Mixed [usd (-179.92)]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tpreceding_comment_lines=""
|
tpreceding_comment_lines=""
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
@ -404,26 +372,10 @@ journal7 = nulljournal {jtxns =
|
|||||||
tdescription="auto transfer to savings",
|
tdescription="auto transfer to savings",
|
||||||
tcomment="",
|
tcomment="",
|
||||||
ttags=[],
|
ttags=[],
|
||||||
tpostings=[
|
tpostings=
|
||||||
Posting {
|
["assets:saving" `post` usd 200
|
||||||
pstatus=False,
|
,"assets:checking" `post` usd (-200)
|
||||||
paccount="assets:saving",
|
],
|
||||||
pamount=(Mixed [usd 200]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount="assets:checking",
|
|
||||||
pamount=(Mixed [usd (-200)]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tpreceding_comment_lines=""
|
tpreceding_comment_lines=""
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
@ -435,26 +387,10 @@ journal7 = nulljournal {jtxns =
|
|||||||
tdescription="poquito mas",
|
tdescription="poquito mas",
|
||||||
tcomment="",
|
tcomment="",
|
||||||
ttags=[],
|
ttags=[],
|
||||||
tpostings=[
|
tpostings=
|
||||||
Posting {
|
["expenses:food:dining" `post` usd 4.82
|
||||||
pstatus=False,
|
,"assets:cash" `post` usd (-4.82)
|
||||||
paccount="expenses:food:dining",
|
],
|
||||||
pamount=(Mixed [usd 4.82]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount="assets:cash",
|
|
||||||
pamount=(Mixed [usd (-4.82)]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tpreceding_comment_lines=""
|
tpreceding_comment_lines=""
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
@ -466,26 +402,10 @@ journal7 = nulljournal {jtxns =
|
|||||||
tdescription="verizon",
|
tdescription="verizon",
|
||||||
tcomment="",
|
tcomment="",
|
||||||
ttags=[],
|
ttags=[],
|
||||||
tpostings=[
|
tpostings=
|
||||||
Posting {
|
["expenses:phone" `post` usd 95.11
|
||||||
pstatus=False,
|
,"assets:checking" `post` usd (-95.11)
|
||||||
paccount="expenses:phone",
|
],
|
||||||
pamount=(Mixed [usd 95.11]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount="assets:checking",
|
|
||||||
pamount=(Mixed [usd (-95.11)]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tpreceding_comment_lines=""
|
tpreceding_comment_lines=""
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
@ -497,26 +417,10 @@ journal7 = nulljournal {jtxns =
|
|||||||
tdescription="discover",
|
tdescription="discover",
|
||||||
tcomment="",
|
tcomment="",
|
||||||
ttags=[],
|
ttags=[],
|
||||||
tpostings=[
|
tpostings=
|
||||||
Posting {
|
["liabilities:credit cards:discover" `post` usd 80
|
||||||
pstatus=False,
|
,"assets:checking" `post` usd (-80)
|
||||||
paccount="liabilities:credit cards:discover",
|
],
|
||||||
pamount=(Mixed [usd 80]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
},
|
|
||||||
Posting {
|
|
||||||
pstatus=False,
|
|
||||||
paccount="assets:checking",
|
|
||||||
pamount=(Mixed [usd (-80)]),
|
|
||||||
pcomment="",
|
|
||||||
ptype=RegularPosting,
|
|
||||||
ptags=[],
|
|
||||||
ptransaction=Nothing
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tpreceding_comment_lines=""
|
tpreceding_comment_lines=""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user