diff --git a/hledger-lib/Hledger/Read/CsvReader.hs b/hledger-lib/Hledger/Read/CsvReader.hs index 12f06bb01..cb339bfcc 100644 --- a/hledger-lib/Hledger/Read/CsvReader.hs +++ b/hledger-lib/Hledger/Read/CsvReader.hs @@ -452,13 +452,19 @@ validateRules :: CsvRules -> ExceptT String IO CsvRules validateRules rules = do unless (isAssigned "date") $ ExceptT $ return $ Left "Please specify (at top level) the date field. Eg: date %1\n" unless ((amount && not (amountin || amountout)) || - (not amount && (amountin && amountout))) - $ ExceptT $ return $ Left "Please specify (at top level) either the amount field, or both the amount-in and amount-out fields. Eg: amount %2\n" + (not amount && (amountin && amountout)) || + balance) + $ ExceptT $ return $ Left $ unlines [ + "Please specify (as a top level CSV rule) either the amount field," + ,"both the amount-in and amount-out fields, or the balance field. Eg:" + ,"amount %2\n" + ] ExceptT $ return $ Right rules where - amount = isAssigned "amount" - amountin = isAssigned "amount-in" + amount = isAssigned "amount" + amountin = isAssigned "amount-in" amountout = isAssigned "amount-out" + balance = isAssigned "balance" || isAssigned "balance1" || isAssigned "balance2" isAssigned f = isJust $ getEffectiveAssignment rules [] f -- parsers diff --git a/hledger-lib/hledger_csv.m4.md b/hledger-lib/hledger_csv.m4.md index b56b0852e..e9b5256dc 100644 --- a/hledger-lib/hledger_csv.m4.md +++ b/hledger-lib/hledger_csv.m4.md @@ -35,7 +35,9 @@ You can override this with the `--rules-file` option. If the rules file does not exist, hledger will auto-create one with some example rules, which you'll need to adjust. -At minimum, the rules file must identify the `date` and `amount` fields. +At minimum, the rules file must identify the date (`date`) and +amount (`amount`, or `amount-in` and `amount-out`, or one of `balance`/`balance1`/`balance2`) +fields. It may also be necessary to specify the date format, and the number of header lines to skip. Eg: ``` fields date, _, _, amount