csv: ignore amount if any amountN's are assigned; improve error msg
The change for hledger 1.17.1 broke one of my csv rules, where I used `amount` but then tried to override it with `amountN`s in a conditional block; the two clashed. Now in that situation any `amountN`s take precedence, causing `amount` to be ignored entirely. Also clarified the "too many non-zero amounts" error message a bit.
This commit is contained in:
parent
f574b782fa
commit
e15eabdf15
@ -880,16 +880,21 @@ getAmount rules record currency p1IsVirtual n =
|
|||||||
-- flip the sign and convert to cost, as they did before 1.17
|
-- flip the sign and convert to cost, as they did before 1.17
|
||||||
, let a' = if f `elem` unnumberedfieldnames && n==2 then costOfMixedAmount (-a) else a
|
, let a' = if f `elem` unnumberedfieldnames && n==2 then costOfMixedAmount (-a) else a
|
||||||
]
|
]
|
||||||
in case nonzeroamounts of
|
-- if there's "amount" and "amountN"s, just discard the former
|
||||||
|
nonzeroamounts'
|
||||||
|
| length nonzeroamounts > 1 = filter ((/="amount").fst) nonzeroamounts
|
||||||
|
| otherwise = nonzeroamounts
|
||||||
|
in case nonzeroamounts' of
|
||||||
[] -> Nothing
|
[] -> Nothing
|
||||||
[(f,a)] | "-out" `isSuffixOf` f -> Just (-a) -- for -out fields, flip the sign
|
[(f,a)] | "-out" `isSuffixOf` f -> Just (-a) -- for -out fields, flip the sign
|
||||||
[(_,a)] -> Just a
|
[(_,a)] -> Just a
|
||||||
fs -> error' $
|
fs -> error' $
|
||||||
"more than one non-zero amount for this record, please ensure just one\n"
|
"more than one non-zero amount for this record, please ensure just one\n"
|
||||||
++ unlines [" " ++ padright 11 f ++ ": " ++ showMixedAmount a
|
|
||||||
++ " from rule: " ++ fromMaybe "" (hledgerField rules record f)
|
|
||||||
| (f,a) <- fs]
|
|
||||||
++ " " ++ showRecord record ++ "\n"
|
++ " " ++ showRecord record ++ "\n"
|
||||||
|
++ unlines [" rule: " ++ f ++ " " ++
|
||||||
|
fromMaybe "" (hledgerField rules record f) ++
|
||||||
|
" amount parsed: " ++ showMixedAmount a -- XXX not sure this is showing all the right info
|
||||||
|
| (f,a) <- fs]
|
||||||
where
|
where
|
||||||
-- | Given a non-empty amount string to parse, along with a possibly
|
-- | Given a non-empty amount string to parse, along with a possibly
|
||||||
-- non-empty currency symbol to prepend, parse as a hledger amount (as
|
-- non-empty currency symbol to prepend, parse as a hledger amount (as
|
||||||
|
|||||||
@ -434,6 +434,7 @@ Also, for compatibility with hledger <1.17:
|
|||||||
`amount` or `amount-in`/`amount-out` with no number sets the amount
|
`amount` or `amount-in`/`amount-out` with no number sets the amount
|
||||||
for postings 1 and 2. For posting 2 the amount is negated, and
|
for postings 1 and 2. For posting 2 the amount is negated, and
|
||||||
converted to cost if there's a [transaction price](journal.html#transaction-prices).
|
converted to cost if there's a [transaction price](journal.html#transaction-prices).
|
||||||
|
But if any numbered `amountN`/`amountN-in`/`amountN-out` fields are present, `amount` is ignored.
|
||||||
|
|
||||||
#### currency
|
#### currency
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user