mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-09 00:15:48 +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
|
- Definitions must come first, one per line, all in one
|
||||||
paragraph. Each is a name and a value separated by whitespace.
|
paragraph. Each is a name and a value separated by whitespace.
|
||||||
Supported names are: base-account, date-field, date-format, status-field,
|
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.
|
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:
|
- The date-format field contains the expected format for the input dates:
|
||||||
this is the same as that accepted by the Haskell
|
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)
|
[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,
|
amountField :: Maybe FieldPosition,
|
||||||
currencyField :: Maybe FieldPosition,
|
currencyField :: Maybe FieldPosition,
|
||||||
baseCurrency :: Maybe String,
|
baseCurrency :: Maybe String,
|
||||||
|
accountField :: Maybe FieldPosition,
|
||||||
baseAccount :: AccountName,
|
baseAccount :: AccountName,
|
||||||
accountRules :: [AccountRule]
|
accountRules :: [AccountRule]
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
@ -55,6 +56,7 @@ nullrules = CsvRules {
|
|||||||
amountField=Nothing,
|
amountField=Nothing,
|
||||||
currencyField=Nothing,
|
currencyField=Nothing,
|
||||||
baseCurrency=Nothing,
|
baseCurrency=Nothing,
|
||||||
|
accountField=Nothing,
|
||||||
baseAccount="unknown",
|
baseAccount="unknown",
|
||||||
accountRules=[]
|
accountRules=[]
|
||||||
}
|
}
|
||||||
@ -174,6 +176,7 @@ definitions = do
|
|||||||
,descriptionfield
|
,descriptionfield
|
||||||
,amountfield
|
,amountfield
|
||||||
,currencyfield
|
,currencyfield
|
||||||
|
,accountfield
|
||||||
,basecurrency
|
,basecurrency
|
||||||
,baseaccount
|
,baseaccount
|
||||||
,commentline
|
,commentline
|
||||||
@ -229,6 +232,14 @@ currencyfield = do
|
|||||||
r <- getState
|
r <- getState
|
||||||
setState r{currencyField=readMay v}
|
setState r{currencyField=readMay v}
|
||||||
|
|
||||||
|
accountfield = do
|
||||||
|
string "account-field"
|
||||||
|
many1 spacenonewline
|
||||||
|
v <- restofline
|
||||||
|
r <- getState
|
||||||
|
setState r{accountField=readMay v}
|
||||||
|
|
||||||
|
|
||||||
basecurrency = do
|
basecurrency = do
|
||||||
string "currency"
|
string "currency"
|
||||||
many1 spacenonewline
|
many1 spacenonewline
|
||||||
@ -288,6 +299,7 @@ transactionFromCsvRecord rules fields =
|
|||||||
desc = maybe "" (atDef "" fields) (descriptionField rules)
|
desc = maybe "" (atDef "" fields) (descriptionField rules)
|
||||||
comment = ""
|
comment = ""
|
||||||
precomment = ""
|
precomment = ""
|
||||||
|
baseacc = maybe (baseAccount rules) (atDef "" fields) (accountField rules)
|
||||||
amountstr = maybe "" (atDef "" fields) (amountField rules)
|
amountstr = maybe "" (atDef "" fields) (amountField rules)
|
||||||
amountstr' = strnegate amountstr where strnegate ('-':s) = s
|
amountstr' = strnegate amountstr where strnegate ('-':s) = s
|
||||||
strnegate s = '-':s
|
strnegate s = '-':s
|
||||||
@ -322,7 +334,7 @@ transactionFromCsvRecord rules fields =
|
|||||||
},
|
},
|
||||||
Posting {
|
Posting {
|
||||||
pstatus=False,
|
pstatus=False,
|
||||||
paccount=baseAccount rules,
|
paccount=baseacc,
|
||||||
pamount=(-baseamount),
|
pamount=(-baseamount),
|
||||||
pcomment="",
|
pcomment="",
|
||||||
ptype=RegularPosting,
|
ptype=RegularPosting,
|
||||||
|
Loading…
Reference in New Issue
Block a user