account2-field

This commit is contained in:
Clint Adams 2011-06-03 01:13:00 +00:00
parent cd0c945454
commit 6544ec02fc
2 changed files with 18 additions and 2 deletions

View File

@ -634,12 +634,17 @@ Notes:
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, effective-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. account2-field, currency. All are optional and will use defaults if not
specified.
- If your file contains data corresponding to several accounts (for example - bulk - If your file contains data corresponding to several accounts (for example - bulk
export from other accounting software), you can use account-field to override 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. value of base-account. When account-field value is empty, base-account will be used.
- If your file contains fields for both accounts in the transaction, you
can use account2-field in addition to account-field. If account2-field
is unspecified, the account-assigning rules will be used (see below).
- 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)

View File

@ -46,6 +46,7 @@ data CsvRules = CsvRules {
currencyField :: Maybe FieldPosition, currencyField :: Maybe FieldPosition,
baseCurrency :: Maybe String, baseCurrency :: Maybe String,
accountField :: Maybe FieldPosition, accountField :: Maybe FieldPosition,
account2Field :: Maybe FieldPosition,
effectiveDateField :: Maybe FieldPosition, effectiveDateField :: Maybe FieldPosition,
baseAccount :: AccountName, baseAccount :: AccountName,
accountRules :: [AccountRule] accountRules :: [AccountRule]
@ -63,6 +64,7 @@ nullrules = CsvRules {
currencyField=Nothing, currencyField=Nothing,
baseCurrency=Nothing, baseCurrency=Nothing,
accountField=Nothing, accountField=Nothing,
account2Field=Nothing,
effectiveDateField=Nothing, effectiveDateField=Nothing,
baseAccount="unknown", baseAccount="unknown",
accountRules=[] accountRules=[]
@ -135,6 +137,7 @@ maxFieldIndex r = maximumDef (-1) $ catMaybes [
,outField r ,outField r
,currencyField r ,currencyField r
,accountField r ,accountField r
,account2Field r
,effectiveDateField r ,effectiveDateField r
] ]
@ -218,6 +221,7 @@ definitions = do
,outfield ,outfield
,currencyfield ,currencyfield
,accountfield ,accountfield
,account2field
,effectivedatefield ,effectivedatefield
,basecurrency ,basecurrency
,baseaccount ,baseaccount
@ -302,6 +306,12 @@ accountfield = do
r <- getState r <- getState
setState r{accountField=readMay v} setState r{accountField=readMay v}
account2field = do
string "account2-field"
many1 spacenonewline
v <- restofline
r <- getState
setState r{account2Field=readMay v}
basecurrency = do basecurrency = do
string "currency" string "currency"
@ -377,7 +387,8 @@ transactionFromCsvRecord rules fields =
baseamount = costOfMixedAmount amount baseamount = costOfMixedAmount amount
unknownacct | (readDef 0 amountstr' :: Double) < 0 = "income:unknown" unknownacct | (readDef 0 amountstr' :: Double) < 0 = "income:unknown"
| otherwise = "expenses:unknown" | otherwise = "expenses:unknown"
(acct,newdesc) = identify (accountRules rules) unknownacct desc (acct',newdesc) = identify (accountRules rules) unknownacct desc
acct = maybe acct' (atDef "" fields) (account2Field rules)
t = Transaction { t = Transaction {
tdate=date, tdate=date,
teffectivedate=effectivedate, teffectivedate=effectivedate,