lib: support generation of (un)balanced virtual postings in csv reader
This commit is contained in:
parent
d8bf72ae73
commit
aa051a05cf
@ -752,7 +752,12 @@ transactionFromCsvRecord sourcepos rules record = t
|
||||
case account of
|
||||
Nothing -> Nothing
|
||||
Just account ->
|
||||
Just $ (number, posting {paccount=account, pamount=fromMaybe missingmixedamt amount, ptransaction=Just t, pbalanceassertion=toAssertion <$> balance, pcomment = comment})
|
||||
Just $ (number, posting {paccount=accountNameWithoutPostingType account
|
||||
, pamount=fromMaybe missingmixedamt amount
|
||||
, ptransaction=Just t
|
||||
, pbalanceassertion=toAssertion <$> balance
|
||||
, pcomment = comment
|
||||
, ptype = accountNamePostingType account})
|
||||
|
||||
parsePosting number =
|
||||
parsePosting' number
|
||||
@ -794,10 +799,13 @@ transactionFromCsvRecord sourcepos rules record = t
|
||||
postings =
|
||||
case postings' of
|
||||
-- To be compatible with the behavior of the old code which allowed two postings only, we enforce
|
||||
-- second posting when rules generated just first of them.
|
||||
-- second posting when rules generated just first of them, and posting is of type that should be balanced.
|
||||
-- When we have srictly first and second posting, but second posting does not have amount, we fill it in.
|
||||
[("1",posting1)] ->
|
||||
[posting1,improveUnknownAccountName (posting{paccount="expenses:unknown", pamount=costOfMixedAmount(-(pamount posting1)), ptransaction=Just t})]
|
||||
case ptype posting1 of
|
||||
VirtualPosting -> [posting1]
|
||||
_ ->
|
||||
[posting1,improveUnknownAccountName (posting{paccount="expenses:unknown", pamount=costOfMixedAmount(-(pamount posting1)), ptransaction=Just t})]
|
||||
[("1",posting1),("2",posting2)] ->
|
||||
case (pamount posting1 == missingmixedamt , pamount posting2 == missingmixedamt) of
|
||||
(False, True) -> [posting1, improveUnknownAccountName (posting2{pamount=costOfMixedAmount(-(pamount posting1))})]
|
||||
|
||||
@ -493,6 +493,40 @@ $ ./hledger-csv
|
||||
|
||||
>=0
|
||||
|
||||
# 23. create unbalanced virtual posting
|
||||
<
|
||||
10/2009/09,Flubber Co,50,123
|
||||
|
||||
RULES
|
||||
fields date, description, amount, balance
|
||||
date-format %d/%Y/%m
|
||||
currency $
|
||||
account1 (assets:myacct)
|
||||
|
||||
$ ./hledger-csv
|
||||
2009/09/10 Flubber Co
|
||||
(assets:myacct) $50 = $123
|
||||
|
||||
>=0
|
||||
|
||||
# 24. create balanced virtual posting
|
||||
<
|
||||
10/2009/09,Flubber Co,50,-50
|
||||
|
||||
RULES
|
||||
fields date, description, amount1, amount2
|
||||
date-format %d/%Y/%m
|
||||
currency $
|
||||
account1 [assets:myacct]
|
||||
account2 [assets:another-acct]
|
||||
|
||||
$ ./hledger-csv
|
||||
2009/09/10 Flubber Co
|
||||
[assets:myacct] $50
|
||||
[assets:another-acct] $-50
|
||||
|
||||
>=0
|
||||
|
||||
|
||||
# . TODO: without --separator gives obscure error
|
||||
# |
|
||||
|
||||
Loading…
Reference in New Issue
Block a user