csv reader: parse parenthesised amounts as negative

This commit is contained in:
Simon Michael 2012-11-26 01:56:01 +00:00
parent c553103caf
commit afb4fb0356

View File

@ -432,7 +432,9 @@ transactionFromCsvRecord rules fields =
precomment = ""
baseacc = maybe (baseAccount rules) (atDef "" fields) (accountField rules)
amountstr = getAmount rules fields
amountstr' = strnegate amountstr where strnegate ('-':s) = s
-- "negate" an amount string. An amount beginning with - or enclosed in parentheses is negative.
amountstr' = strnegate amountstr where strnegate ('(':s) | not (null s) && last s == ')' = init s
strnegate ('-':s) = s
strnegate s = '-':s
currency = maybe (fromMaybe "" $ baseCurrency rules) (atDef "" fields) (currencyField rules)
amountstr'' = currency ++ amountstr'