mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 15:14:49 +03:00
Added account-field to Convert.hs
This commit is contained in:
parent
e37d3a522d
commit
c78fe9dd5d
@ -561,9 +561,13 @@ Notes:
|
||||
- Definitions must come first, one per line, all in one
|
||||
paragraph. Each is a name and a value separated by whitespace.
|
||||
Supported names are: base-account, date-field, date-format, status-field,
|
||||
code-field, description-field, amount-field, currency-field,
|
||||
code-field, description-field, amount-field, currency-field, account-field,
|
||||
currency. All are optional and will use defaults if not specified.
|
||||
|
||||
- If your file contains data corresponding to several accounts (for example - bulk
|
||||
export from other accounting software), you can use account-field to override
|
||||
value of base-account. When account-field value is empty, base-account will be used.
|
||||
|
||||
- The date-format field contains the expected format for the input dates:
|
||||
this is the same as that accepted by the Haskell
|
||||
[formatTime](http://hackage.haskell.org/packages/archive/time/latest/doc/html/Data-Time-Format.html#v:formatTime)
|
||||
|
@ -42,6 +42,7 @@ data CsvRules = CsvRules {
|
||||
amountField :: Maybe FieldPosition,
|
||||
currencyField :: Maybe FieldPosition,
|
||||
baseCurrency :: Maybe String,
|
||||
accountField :: Maybe FieldPosition,
|
||||
baseAccount :: AccountName,
|
||||
accountRules :: [AccountRule]
|
||||
} deriving (Show, Eq)
|
||||
@ -55,6 +56,7 @@ nullrules = CsvRules {
|
||||
amountField=Nothing,
|
||||
currencyField=Nothing,
|
||||
baseCurrency=Nothing,
|
||||
accountField=Nothing,
|
||||
baseAccount="unknown",
|
||||
accountRules=[]
|
||||
}
|
||||
@ -174,6 +176,7 @@ definitions = do
|
||||
,descriptionfield
|
||||
,amountfield
|
||||
,currencyfield
|
||||
,accountfield
|
||||
,basecurrency
|
||||
,baseaccount
|
||||
,commentline
|
||||
@ -229,6 +232,14 @@ currencyfield = do
|
||||
r <- getState
|
||||
setState r{currencyField=readMay v}
|
||||
|
||||
accountfield = do
|
||||
string "account-field"
|
||||
many1 spacenonewline
|
||||
v <- restofline
|
||||
r <- getState
|
||||
setState r{accountField=readMay v}
|
||||
|
||||
|
||||
basecurrency = do
|
||||
string "currency"
|
||||
many1 spacenonewline
|
||||
@ -288,6 +299,7 @@ transactionFromCsvRecord rules fields =
|
||||
desc = maybe "" (atDef "" fields) (descriptionField rules)
|
||||
comment = ""
|
||||
precomment = ""
|
||||
baseacc = maybe (baseAccount rules) (atDef "" fields) (accountField rules)
|
||||
amountstr = maybe "" (atDef "" fields) (amountField rules)
|
||||
amountstr' = strnegate amountstr where strnegate ('-':s) = s
|
||||
strnegate s = '-':s
|
||||
@ -322,7 +334,7 @@ transactionFromCsvRecord rules fields =
|
||||
},
|
||||
Posting {
|
||||
pstatus=False,
|
||||
paccount=baseAccount rules,
|
||||
paccount=baseacc,
|
||||
pamount=(-baseamount),
|
||||
pcomment="",
|
||||
ptype=RegularPosting,
|
||||
@ -403,4 +415,4 @@ tests_Hledger_Cli_Convert = TestList [
|
||||
-- ]
|
||||
-- })
|
||||
|
||||
]
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user