mirror of
https://github.com/simonmichael/hledger.git
synced 2025-01-04 00:07:29 +03:00
Added support for effective-date-field to the "convert" operation
This commit is contained in:
parent
c78fe9dd5d
commit
b9ae208bd5
@ -560,7 +560,7 @@ 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, effective-date-field, date-format, status-field,
|
||||||
code-field, description-field, amount-field, currency-field, account-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.
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ data CsvRules = CsvRules {
|
|||||||
currencyField :: Maybe FieldPosition,
|
currencyField :: Maybe FieldPosition,
|
||||||
baseCurrency :: Maybe String,
|
baseCurrency :: Maybe String,
|
||||||
accountField :: Maybe FieldPosition,
|
accountField :: Maybe FieldPosition,
|
||||||
|
effectiveDateField :: Maybe FieldPosition,
|
||||||
baseAccount :: AccountName,
|
baseAccount :: AccountName,
|
||||||
accountRules :: [AccountRule]
|
accountRules :: [AccountRule]
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
@ -57,6 +58,7 @@ nullrules = CsvRules {
|
|||||||
currencyField=Nothing,
|
currencyField=Nothing,
|
||||||
baseCurrency=Nothing,
|
baseCurrency=Nothing,
|
||||||
accountField=Nothing,
|
accountField=Nothing,
|
||||||
|
effectiveDateField=Nothing,
|
||||||
baseAccount="unknown",
|
baseAccount="unknown",
|
||||||
accountRules=[]
|
accountRules=[]
|
||||||
}
|
}
|
||||||
@ -114,6 +116,7 @@ maxFieldIndex r = maximumDef (-1) $ catMaybes [
|
|||||||
,amountField r
|
,amountField r
|
||||||
,currencyField r
|
,currencyField r
|
||||||
,accountField r
|
,accountField r
|
||||||
|
,effectiveDateField r
|
||||||
]
|
]
|
||||||
|
|
||||||
rulesFileFor :: FilePath -> FilePath
|
rulesFileFor :: FilePath -> FilePath
|
||||||
@ -177,6 +180,7 @@ definitions = do
|
|||||||
,amountfield
|
,amountfield
|
||||||
,currencyfield
|
,currencyfield
|
||||||
,accountfield
|
,accountfield
|
||||||
|
,effectivedatefield
|
||||||
,basecurrency
|
,basecurrency
|
||||||
,baseaccount
|
,baseaccount
|
||||||
,commentline
|
,commentline
|
||||||
@ -190,6 +194,13 @@ datefield = do
|
|||||||
r <- getState
|
r <- getState
|
||||||
setState r{dateField=readMay v}
|
setState r{dateField=readMay v}
|
||||||
|
|
||||||
|
effectivedatefield = do
|
||||||
|
string "effective-date-field"
|
||||||
|
many1 spacenonewline
|
||||||
|
v <- restofline
|
||||||
|
r <- getState
|
||||||
|
setState r{effectiveDateField=readMay v}
|
||||||
|
|
||||||
dateformat = do
|
dateformat = do
|
||||||
string "date-format"
|
string "date-format"
|
||||||
many1 spacenonewline
|
many1 spacenonewline
|
||||||
@ -294,6 +305,8 @@ transactionFromCsvRecord :: CsvRules -> CsvRecord -> Transaction
|
|||||||
transactionFromCsvRecord rules fields =
|
transactionFromCsvRecord rules fields =
|
||||||
let
|
let
|
||||||
date = parsedate $ normaliseDate (dateFormat rules) $ maybe "1900/1/1" (atDef "" fields) (dateField rules)
|
date = parsedate $ normaliseDate (dateFormat rules) $ maybe "1900/1/1" (atDef "" fields) (dateField rules)
|
||||||
|
effectivedate = do idx <- effectiveDateField rules
|
||||||
|
return $ parsedate $ normaliseDate (dateFormat rules) $ (atDef "" fields) idx
|
||||||
status = maybe False (null . strip . (atDef "" fields)) (statusField rules)
|
status = maybe False (null . strip . (atDef "" fields)) (statusField rules)
|
||||||
code = maybe "" (atDef "" fields) (codeField rules)
|
code = maybe "" (atDef "" fields) (codeField rules)
|
||||||
desc = maybe "" (atDef "" fields) (descriptionField rules)
|
desc = maybe "" (atDef "" fields) (descriptionField rules)
|
||||||
@ -315,7 +328,7 @@ transactionFromCsvRecord rules fields =
|
|||||||
(acct,newdesc) = identify (accountRules rules) unknownacct desc
|
(acct,newdesc) = identify (accountRules rules) unknownacct desc
|
||||||
t = Transaction {
|
t = Transaction {
|
||||||
tdate=date,
|
tdate=date,
|
||||||
teffectivedate=Nothing,
|
teffectivedate=effectivedate,
|
||||||
tstatus=status,
|
tstatus=status,
|
||||||
tcode=code,
|
tcode=code,
|
||||||
tdescription=newdesc,
|
tdescription=newdesc,
|
||||||
|
Loading…
Reference in New Issue
Block a user