lib: better resolution of csv field aliases ("balance" vs "balance1", etc)
This commit is contained in:
parent
205ff9d2d6
commit
94f912e558
@ -767,34 +767,24 @@ transactionFromCsvRecord sourcepos rules record = t
|
|||||||
("balance"++number)
|
("balance"++number)
|
||||||
("comment" ++ number)
|
("comment" ++ number)
|
||||||
|
|
||||||
postingLegacy = parsePosting' "" "account1" "amount" "amount-in" "amount-out" "balance" "comment1"
|
withAlias fld alias =
|
||||||
posting1' = parsePosting "1"
|
case (mfieldtemplate fld, mfieldtemplate alias) of
|
||||||
posting1 =
|
(Just fld, Just alias) -> error' $ unlines
|
||||||
case (postingLegacy,posting1') of
|
[ "error: both \"" ++ fld ++ "\" and \"" ++ alias ++ "\" have values."
|
||||||
(Just (_,legacy), Nothing) -> Just ("1", legacy)
|
, showRecord record
|
||||||
(Nothing, Just (_,posting1)) -> Just ("1", posting1)
|
, showRules rules record
|
||||||
(Just (_,legacy), Just (_,posting1)) ->
|
]
|
||||||
-- Here we merge legacy fields such as "amount" with "amount1", etc
|
(Nothing, Just _) -> alias
|
||||||
-- Account and Comment would be the same by construction
|
(_, Nothing) -> fld
|
||||||
let balanceassertion = (pbalanceassertion legacy) `or` (pbalanceassertion posting1)
|
|
||||||
amount =
|
posting1 = parsePosting' "1"
|
||||||
let al = pamount legacy
|
("account1" `withAlias` "account")
|
||||||
a1 = pamount posting1
|
("amount1" `withAlias` "amount")
|
||||||
in
|
("amount1-in" `withAlias` "amount-in")
|
||||||
if al == a1 then al
|
("amount1-out" `withAlias` "amount-out")
|
||||||
else
|
("balance1" `withAlias` "balance")
|
||||||
case (isZeroMixedAmount al, isZeroMixedAmount a1) of
|
"comment1" -- comment1 does not have legacy alias
|
||||||
(True, _) -> a1
|
|
||||||
(False, True) -> al
|
|
||||||
(False, False) ->
|
|
||||||
error' $ unlines [ "amount/amount-in/amount-out and amount1/amount1-in/amount1-out produced conflicting values"
|
|
||||||
, showRecord record
|
|
||||||
, showRules rules record
|
|
||||||
, "amount/amount-in/amount-out is " ++ showMixedAmount al
|
|
||||||
, "amount1/amount1-in/amount1-out is " ++ showMixedAmount a1
|
|
||||||
]
|
|
||||||
in Just $ ("1", posting {paccount=paccount posting1, pamount=amount, ptransaction=Just t, pbalanceassertion=balanceassertion, pcomment = pcomment posting1})
|
|
||||||
(Nothing, Nothing) -> Nothing
|
|
||||||
postings' = catMaybes $ posting1:[ parsePosting i | x<-[2..9], let i = show x]
|
postings' = catMaybes $ posting1:[ parsePosting i | x<-[2..9], let i = show x]
|
||||||
|
|
||||||
improveUnknownAccountName p =
|
improveUnknownAccountName p =
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user