From 6544ec02fca8cc3a9e4be1d2569ecec5a15910dc Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Fri, 3 Jun 2011 01:13:00 +0000 Subject: [PATCH] account2-field --- MANUAL.md | 7 ++++++- hledger/Hledger/Cli/Convert.hs | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/MANUAL.md b/MANUAL.md index bc973c1a6..778115148 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -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) diff --git a/hledger/Hledger/Cli/Convert.hs b/hledger/Hledger/Cli/Convert.hs index 7256388af..0635ca4d8 100644 --- a/hledger/Hledger/Cli/Convert.hs +++ b/hledger/Hledger/Cli/Convert.hs @@ -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,