;csv: refactor: more transactionFromCsvRecord cleanups
This commit is contained in:
parent
93358d72b4
commit
be5fc09ebb
@ -816,10 +816,8 @@ transactionFromCsvRecord sourcepos rules record = t
|
|||||||
(either (balanceerror n str) id $
|
(either (balanceerror n str) id $
|
||||||
runParser (evalStateT (amountp <* eof) mempty) "" $
|
runParser (evalStateT (amountp <* eof) mempty) "" $
|
||||||
T.pack $ (currency++) $ simplifySign str
|
T.pack $ (currency++) $ simplifySign str
|
||||||
,nullsourcepos) -- XXX parse position to show when assertion fails.
|
,nullsourcepos) -- XXX parse position to show when assertion fails,
|
||||||
-- We don't know the posting's line number, but we
|
-- the csv record's line number would be good
|
||||||
-- could show the csv record's line number, probably
|
|
||||||
-- more useful, though perhaps confusing.
|
|
||||||
where
|
where
|
||||||
balanceerror n str err = error' $ unlines
|
balanceerror n str err = error' $ unlines
|
||||||
["error: could not parse \""++str++"\" as balance"++n++" amount"
|
["error: could not parse \""++str++"\" as balance"++n++" amount"
|
||||||
@ -829,24 +827,24 @@ transactionFromCsvRecord sourcepos rules record = t
|
|||||||
,"the parse error is: "++customErrorBundlePretty err
|
,"the parse error is: "++customErrorBundlePretty err
|
||||||
]
|
]
|
||||||
comment = T.pack $ maybe "" render $ mfieldtemplate commentFld
|
comment = T.pack $ maybe "" render $ mfieldtemplate commentFld
|
||||||
maccount' = ((T.pack . render) <$>
|
maccount = ((T.pack . render) <$>
|
||||||
(mfieldtemplate accountFld `or` mdirective ("default-account" ++ number)))
|
(mfieldtemplate accountFld `or` mdirective ("default-account" ++ number)))
|
||||||
-- figure out the account name to use for this posting, if any, and
|
-- figure out the account name to use for this posting, if any, and
|
||||||
-- whether it is the unknown account which may be improved later,
|
-- whether it is the default unknown account, which may be improved
|
||||||
-- when we know the posting's final amount.
|
-- later, or an explicitly set account, which may not.
|
||||||
maccountAndIsFinal :: Maybe (AccountName, Bool) =
|
maccountAndIsFinal :: Maybe (AccountName, Bool) =
|
||||||
case maccount' of
|
case maccount of
|
||||||
-- accountN is set to the empty string - no posting will be generated
|
-- accountN is set to the empty string - no posting will be generated
|
||||||
Just "" -> Nothing
|
Just "" -> Nothing
|
||||||
-- accountN is set (possibly to "expenses:unknown" ! #1192) -
|
-- accountN is set (possibly to "expenses:unknown"! cf #1192) -
|
||||||
-- don't let it be changed.
|
-- mark it final
|
||||||
Just a -> Just (a, True)
|
Just a -> Just (a, True)
|
||||||
-- accountN is unset
|
-- accountN is unset
|
||||||
Nothing ->
|
Nothing ->
|
||||||
case (mamount, mbalance) of
|
case (mamount, mbalance) of
|
||||||
-- amountN is set, or implied by balanceN - set accountN to
|
-- amountN is set, or implied by balanceN - set accountN to
|
||||||
-- set to the default unknown account (expenses:unknown)
|
-- the default unknown account ("expenses:unknown") and
|
||||||
-- and allow it to be improved later
|
-- allow it to be improved later
|
||||||
(Just _, _) -> Just (unknownExpenseAccount, False)
|
(Just _, _) -> Just (unknownExpenseAccount, False)
|
||||||
(_, Just _) -> Just (unknownExpenseAccount, False)
|
(_, Just _) -> Just (unknownExpenseAccount, False)
|
||||||
-- amountN is also unset - no posting will be generated
|
-- amountN is also unset - no posting will be generated
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user