lib: rename, reposition tprecedingcomment field
This commit is contained in:
parent
cd1455e9ea
commit
6f36702141
@ -1063,7 +1063,7 @@ Right samplejournal = journalBalanceTransactions False $
|
||||
["assets:bank:checking" `post` usd 1
|
||||
,"income:salary" `post` missingamt
|
||||
],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
,
|
||||
txnTieKnot $ Transaction {
|
||||
@ -1080,7 +1080,7 @@ Right samplejournal = journalBalanceTransactions False $
|
||||
["assets:bank:checking" `post` usd 1
|
||||
,"income:gifts" `post` missingamt
|
||||
],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
,
|
||||
txnTieKnot $ Transaction {
|
||||
@ -1097,7 +1097,7 @@ Right samplejournal = journalBalanceTransactions False $
|
||||
["assets:bank:saving" `post` usd 1
|
||||
,"assets:bank:checking" `post` usd (-1)
|
||||
],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
,
|
||||
txnTieKnot $ Transaction {
|
||||
@ -1114,7 +1114,7 @@ Right samplejournal = journalBalanceTransactions False $
|
||||
,"expenses:supplies" `post` usd 1
|
||||
,"assets:cash" `post` missingamt
|
||||
],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
,
|
||||
txnTieKnot $ Transaction {
|
||||
@ -1130,7 +1130,7 @@ Right samplejournal = journalBalanceTransactions False $
|
||||
tpostings=["assets:bank:checking" `post` usd 1
|
||||
,"liabilities:debts" `post` usd (-1)
|
||||
],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
,
|
||||
txnTieKnot $ Transaction {
|
||||
@ -1146,7 +1146,7 @@ Right samplejournal = journalBalanceTransactions False $
|
||||
tpostings=["liabilities:debts" `post` usd 1
|
||||
,"assets:bank:checking" `post` usd (-1)
|
||||
],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ entryFromTimeclockInOut i o
|
||||
tcomment = "",
|
||||
ttags = [],
|
||||
tpostings = ps,
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
itime = tldatetime i
|
||||
otime = tldatetime o
|
||||
|
||||
@ -90,7 +90,7 @@ nulltransaction = Transaction {
|
||||
tcomment="",
|
||||
ttags=[],
|
||||
tpostings=[],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
|
||||
{-|
|
||||
@ -689,10 +689,10 @@ tests_Transaction = tests "Transaction" [
|
||||
|
||||
,tests "showTransaction" [
|
||||
test "show a balanced transaction, eliding last amount" $
|
||||
let t = Transaction 0 nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "coopportunity" "" []
|
||||
let t = Transaction 0 "" nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "coopportunity" "" []
|
||||
[posting{paccount="expenses:food:groceries", pamount=Mixed [usd 47.18], ptransaction=Just t}
|
||||
,posting{paccount="assets:checking", pamount=Mixed [usd (-47.18)], ptransaction=Just t}
|
||||
] ""
|
||||
]
|
||||
in
|
||||
showTransaction t
|
||||
`is`
|
||||
@ -704,10 +704,10 @@ tests_Transaction = tests "Transaction" [
|
||||
]
|
||||
|
||||
,test "show a balanced transaction, no eliding" $
|
||||
(let t = Transaction 0 nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "coopportunity" "" []
|
||||
(let t = Transaction 0 "" nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "coopportunity" "" []
|
||||
[posting{paccount="expenses:food:groceries", pamount=Mixed [usd 47.18], ptransaction=Just t}
|
||||
,posting{paccount="assets:checking", pamount=Mixed [usd (-47.18)], ptransaction=Just t}
|
||||
] ""
|
||||
]
|
||||
in showTransactionUnelided t)
|
||||
`is`
|
||||
(unlines
|
||||
@ -720,10 +720,10 @@ tests_Transaction = tests "Transaction" [
|
||||
-- document some cases that arise in debug/testing:
|
||||
,test "show an unbalanced transaction, should not elide" $
|
||||
(showTransaction
|
||||
(txnTieKnot $ Transaction 0 nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "coopportunity" "" []
|
||||
(txnTieKnot $ Transaction 0 "" nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "coopportunity" "" []
|
||||
[posting{paccount="expenses:food:groceries", pamount=Mixed [usd 47.18]}
|
||||
,posting{paccount="assets:checking", pamount=Mixed [usd (-47.19)]}
|
||||
] ""))
|
||||
]))
|
||||
`is`
|
||||
(unlines
|
||||
["2007/01/28 coopportunity"
|
||||
@ -734,9 +734,9 @@ tests_Transaction = tests "Transaction" [
|
||||
|
||||
,test "show an unbalanced transaction with one posting, should not elide" $
|
||||
(showTransaction
|
||||
(txnTieKnot $ Transaction 0 nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "coopportunity" "" []
|
||||
(txnTieKnot $ Transaction 0 "" nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "coopportunity" "" []
|
||||
[posting{paccount="expenses:food:groceries", pamount=Mixed [usd 47.18]}
|
||||
] ""))
|
||||
]))
|
||||
`is`
|
||||
(unlines
|
||||
["2007/01/28 coopportunity"
|
||||
@ -746,9 +746,9 @@ tests_Transaction = tests "Transaction" [
|
||||
|
||||
,test "show a transaction with one posting and a missing amount" $
|
||||
(showTransaction
|
||||
(txnTieKnot $ Transaction 0 nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "coopportunity" "" []
|
||||
(txnTieKnot $ Transaction 0 "" nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "coopportunity" "" []
|
||||
[posting{paccount="expenses:food:groceries", pamount=missingmixedamt}
|
||||
] ""))
|
||||
]))
|
||||
`is`
|
||||
(unlines
|
||||
["2007/01/28 coopportunity"
|
||||
@ -758,10 +758,10 @@ tests_Transaction = tests "Transaction" [
|
||||
|
||||
,test "show a transaction with a priced commodityless amount" $
|
||||
(showTransaction
|
||||
(txnTieKnot $ Transaction 0 nullsourcepos (parsedate "2010/01/01") Nothing Unmarked "" "x" "" []
|
||||
(txnTieKnot $ Transaction 0 "" nullsourcepos (parsedate "2010/01/01") Nothing Unmarked "" "x" "" []
|
||||
[posting{paccount="a", pamount=Mixed [num 1 `at` (usd 2 `withPrecision` 0)]}
|
||||
,posting{paccount="b", pamount= missingmixedamt}
|
||||
] ""))
|
||||
]))
|
||||
`is`
|
||||
(unlines
|
||||
["2010/01/01 x"
|
||||
@ -774,95 +774,95 @@ tests_Transaction = tests "Transaction" [
|
||||
,tests "balanceTransaction" [
|
||||
test "detect unbalanced entry, sign error" $
|
||||
(expectLeft $ balanceTransaction Nothing
|
||||
(Transaction 0 nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "test" "" []
|
||||
(Transaction 0 "" nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "test" "" []
|
||||
[posting{paccount="a", pamount=Mixed [usd 1]}
|
||||
,posting{paccount="b", pamount=Mixed [usd 1]}
|
||||
] ""))
|
||||
]))
|
||||
|
||||
,test "detect unbalanced entry, multiple missing amounts" $
|
||||
(expectLeft $ balanceTransaction Nothing
|
||||
(Transaction 0 nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "test" "" []
|
||||
(Transaction 0 "" nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "test" "" []
|
||||
[posting{paccount="a", pamount=missingmixedamt}
|
||||
,posting{paccount="b", pamount=missingmixedamt}
|
||||
] ""))
|
||||
]))
|
||||
|
||||
,test "one missing amount is inferred" $
|
||||
(pamount . last . tpostings <$> balanceTransaction
|
||||
Nothing
|
||||
(Transaction 0 nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "" "" []
|
||||
(Transaction 0 "" nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "" "" []
|
||||
[posting{paccount="a", pamount=Mixed [usd 1]}
|
||||
,posting{paccount="b", pamount=missingmixedamt}
|
||||
] ""))
|
||||
]))
|
||||
`is` Right (Mixed [usd (-1)])
|
||||
|
||||
,test "conversion price is inferred" $
|
||||
(pamount . head . tpostings <$> balanceTransaction
|
||||
Nothing
|
||||
(Transaction 0 nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "" "" []
|
||||
(Transaction 0 "" nullsourcepos (parsedate "2007/01/28") Nothing Unmarked "" "" "" []
|
||||
[posting{paccount="a", pamount=Mixed [usd 1.35]}
|
||||
,posting{paccount="b", pamount=Mixed [eur (-1)]}
|
||||
] ""))
|
||||
]))
|
||||
`is` Right (Mixed [usd 1.35 @@ (eur 1 `withPrecision` maxprecision)])
|
||||
|
||||
,test "balanceTransaction balances based on cost if there are unit prices" $
|
||||
expectRight $
|
||||
balanceTransaction Nothing (Transaction 0 nullsourcepos (parsedate "2011/01/01") Nothing Unmarked "" "" "" []
|
||||
balanceTransaction Nothing (Transaction 0 "" nullsourcepos (parsedate "2011/01/01") Nothing Unmarked "" "" "" []
|
||||
[posting{paccount="a", pamount=Mixed [usd 1 `at` eur 2]}
|
||||
,posting{paccount="a", pamount=Mixed [usd (-2) `at` eur 1]}
|
||||
] "")
|
||||
])
|
||||
|
||||
,test "balanceTransaction balances based on cost if there are total prices" $
|
||||
expectRight $
|
||||
balanceTransaction Nothing (Transaction 0 nullsourcepos (parsedate "2011/01/01") Nothing Unmarked "" "" "" []
|
||||
balanceTransaction Nothing (Transaction 0 "" nullsourcepos (parsedate "2011/01/01") Nothing Unmarked "" "" "" []
|
||||
[posting{paccount="a", pamount=Mixed [usd 1 @@ eur 1]}
|
||||
,posting{paccount="a", pamount=Mixed [usd (-2) @@ eur 1]}
|
||||
] "")
|
||||
])
|
||||
]
|
||||
|
||||
,tests "isTransactionBalanced" [
|
||||
test "detect balanced" $ expect $
|
||||
isTransactionBalanced Nothing $ Transaction 0 nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
isTransactionBalanced Nothing $ Transaction 0 "" nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
[posting{paccount="b", pamount=Mixed [usd 1.00]}
|
||||
,posting{paccount="c", pamount=Mixed [usd (-1.00)]}
|
||||
] ""
|
||||
]
|
||||
|
||||
,test "detect unbalanced" $ expect $
|
||||
not $ isTransactionBalanced Nothing $ Transaction 0 nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
not $ isTransactionBalanced Nothing $ Transaction 0 "" nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
[posting{paccount="b", pamount=Mixed [usd 1.00]}
|
||||
,posting{paccount="c", pamount=Mixed [usd (-1.01)]}
|
||||
] ""
|
||||
]
|
||||
|
||||
,test "detect unbalanced, one posting" $ expect $
|
||||
not $ isTransactionBalanced Nothing $ Transaction 0 nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
not $ isTransactionBalanced Nothing $ Transaction 0 "" nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
[posting{paccount="b", pamount=Mixed [usd 1.00]}
|
||||
] ""
|
||||
]
|
||||
|
||||
,test "one zero posting is considered balanced for now" $ expect $
|
||||
isTransactionBalanced Nothing $ Transaction 0 nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
isTransactionBalanced Nothing $ Transaction 0 "" nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
[posting{paccount="b", pamount=Mixed [usd 0]}
|
||||
] ""
|
||||
]
|
||||
|
||||
,test "virtual postings don't need to balance" $ expect $
|
||||
isTransactionBalanced Nothing $ Transaction 0 nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
isTransactionBalanced Nothing $ Transaction 0 "" nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
[posting{paccount="b", pamount=Mixed [usd 1.00]}
|
||||
,posting{paccount="c", pamount=Mixed [usd (-1.00)]}
|
||||
,posting{paccount="d", pamount=Mixed [usd 100], ptype=VirtualPosting}
|
||||
] ""
|
||||
]
|
||||
|
||||
,test "balanced virtual postings need to balance among themselves" $ expect $
|
||||
not $ isTransactionBalanced Nothing $ Transaction 0 nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
not $ isTransactionBalanced Nothing $ Transaction 0 "" nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
[posting{paccount="b", pamount=Mixed [usd 1.00]}
|
||||
,posting{paccount="c", pamount=Mixed [usd (-1.00)]}
|
||||
,posting{paccount="d", pamount=Mixed [usd 100], ptype=BalancedVirtualPosting}
|
||||
] ""
|
||||
]
|
||||
|
||||
,test "balanced virtual postings need to balance among themselves (2)" $ expect $
|
||||
isTransactionBalanced Nothing $ Transaction 0 nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
isTransactionBalanced Nothing $ Transaction 0 "" nullsourcepos (parsedate "2009/01/01") Nothing Unmarked "" "a" "" []
|
||||
[posting{paccount="b", pamount=Mixed [usd 1.00]}
|
||||
,posting{paccount="c", pamount=Mixed [usd (-1.00)]}
|
||||
,posting{paccount="d", pamount=Mixed [usd 100], ptype=BalancedVirtualPosting}
|
||||
,posting{paccount="3", pamount=Mixed [usd (-100)], ptype=BalancedVirtualPosting}
|
||||
] ""
|
||||
]
|
||||
|
||||
]
|
||||
|
||||
|
||||
@ -302,8 +302,9 @@ instance NFData GenericSourcePos
|
||||
-- prevents the constraint ‘(Data p0)’ from being solved.
|
||||
-- Probable fix: use a type annotation to specify what ‘p0’ should be.
|
||||
data Transaction = Transaction {
|
||||
tindex :: Integer, -- ^ this transaction's 1-based position in the input stream, or 0 when not available
|
||||
tsourcepos :: GenericSourcePos,
|
||||
tindex :: Integer, -- ^ this transaction's 1-based position in the transaction stream, or 0 when not available
|
||||
tprecedingcomment :: Text, -- ^ any comment lines immediately preceding this transaction
|
||||
tsourcepos :: GenericSourcePos, -- ^ the file position where the date starts
|
||||
tdate :: Day,
|
||||
tdate2 :: Maybe Day,
|
||||
tstatus :: Status,
|
||||
@ -311,8 +312,7 @@ data Transaction = Transaction {
|
||||
tdescription :: Text,
|
||||
tcomment :: Text, -- ^ this transaction's comment lines, as a single non-indented multi-line string
|
||||
ttags :: [Tag], -- ^ tag names and values, extracted from the comment
|
||||
tpostings :: [Posting], -- ^ this transaction's postings
|
||||
tpreceding_comment_lines :: Text -- ^ any comment lines immediately preceding this transaction
|
||||
tpostings :: [Posting] -- ^ this transaction's postings
|
||||
} deriving (Eq,Typeable,Data,Generic,Show)
|
||||
|
||||
instance NFData Transaction
|
||||
|
||||
@ -746,7 +746,7 @@ transactionFromCsvRecord sourcepos rules record = t
|
||||
tcode = T.pack code,
|
||||
tdescription = T.pack description,
|
||||
tcomment = T.pack comment,
|
||||
tpreceding_comment_lines = T.pack precomment,
|
||||
tprecedingcomment = T.pack precomment,
|
||||
tpostings =
|
||||
[posting {paccount=account1, pamount=amount1, ptransaction=Just t, pbalanceassertion=toAssertion <$> balance}
|
||||
,posting {paccount=account2, pamount=amount2, ptransaction=Just t}
|
||||
|
||||
@ -573,7 +573,7 @@ transactionp = do
|
||||
postings <- postingsp (Just year)
|
||||
endpos <- getSourcePos
|
||||
let sourcepos = journalSourcePos startpos endpos
|
||||
return $ txnTieKnot $ Transaction 0 sourcepos date edate status code description comment tags postings ""
|
||||
return $ txnTieKnot $ Transaction 0 "" sourcepos date edate status code description comment tags postings
|
||||
|
||||
--- ** postings
|
||||
|
||||
@ -760,7 +760,7 @@ tests_JournalReader = tests "JournalReader" [
|
||||
])
|
||||
nulltransaction{
|
||||
tsourcepos=JournalSourcePos "" (1,7), -- XXX why 7 here ?
|
||||
tpreceding_comment_lines="",
|
||||
tprecedingcomment="",
|
||||
tdate=fromGregorian 2012 5 14,
|
||||
tdate2=Just $ fromGregorian 2012 5 15,
|
||||
tstatus=Unmarked,
|
||||
|
||||
@ -198,7 +198,7 @@ Right samplejournal2 =
|
||||
[posting {paccount="assets:bank:checking", pamount=Mixed [usd 1]}
|
||||
,posting {paccount="income:salary", pamount=missingmixedamt}
|
||||
],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -537,7 +537,7 @@ journal7 = nulljournal {jtxns =
|
||||
["assets:cash" `post` usd 4.82
|
||||
,"equity:opening balances" `post` usd (-4.82)
|
||||
],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
,
|
||||
txnTieKnot Transaction {
|
||||
@ -554,7 +554,7 @@ journal7 = nulljournal {jtxns =
|
||||
["expenses:vacation" `post` usd 179.92
|
||||
,"assets:checking" `post` usd (-179.92)
|
||||
],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
,
|
||||
txnTieKnot Transaction {
|
||||
@ -571,7 +571,7 @@ journal7 = nulljournal {jtxns =
|
||||
["assets:saving" `post` usd 200
|
||||
,"assets:checking" `post` usd (-200)
|
||||
],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
,
|
||||
txnTieKnot Transaction {
|
||||
@ -588,7 +588,7 @@ journal7 = nulljournal {jtxns =
|
||||
["expenses:food:dining" `post` usd 4.82
|
||||
,"assets:cash" `post` usd (-4.82)
|
||||
],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
,
|
||||
txnTieKnot Transaction {
|
||||
@ -605,7 +605,7 @@ journal7 = nulljournal {jtxns =
|
||||
["expenses:phone" `post` usd 95.11
|
||||
,"assets:checking" `post` usd (-95.11)
|
||||
],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
,
|
||||
txnTieKnot Transaction {
|
||||
@ -622,7 +622,7 @@ journal7 = nulljournal {jtxns =
|
||||
["liabilities:credit cards:discover" `post` usd 80
|
||||
,"assets:checking" `post` usd (-80)
|
||||
],
|
||||
tpreceding_comment_lines=""
|
||||
tprecedingcomment=""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user