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.
Supported names are: base-account, date-field, effective-date-field, date-format, status-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
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.
- 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:
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)

View File

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