howeyc / ledger

Command line double-entry accounting program
https://howeyc.github.io/ledger/
ISC License
461 stars 43 forks source link

CSV import #30

Closed porjo closed 2 years ago

porjo commented 2 years ago

Disclaimer: I'm just getting started with Ledger and plain text accounting

My bank produces CSV output like this:

Date,Description,Credit,Debit,Balance
07/03/2022,xxxxxxxxxxx,500.00,,739.64
07/03/2022,yyyyyyyyyyy,,-5.00,239.64
07/03/2022,zzzzzzzzz,50.00,,244.64

My initial leger.dat file is just an opening balance:

2022/02/06 * Opening Balance
    Assets:Paywave                   $92.40

After adjusting header row (Date -> Transaction Date, Credit -> Amount), I can import and get Ledger output like this:

$ ./ledger -f ledger.dat import --date-format "02/01/2006" Paywave trans.csv
2022/03/07 xxxxxxxxxxxxxx
    Assets                                                                500.00
    Assets:Paywave                   $92.40                              -500.00

2022/03/07 yyyyyyyyyy
    Assets                                                                500.00
    Assets:Paywave                   $92.40                              -500.00

2022/03/07 zzzzzzzzzz
    Assets                                                                 50.00
    Assets:Paywave                   $92.40                               -50.00

Some issues:

howeyc commented 2 years ago

Yeah, a couple issues:

1) This program does double-entry accounting, and your starting file is not valid, which I should fix my program to warn/error. You need at least two postings (lines) for each transaction. Your 92.40 has to come from somewhere, so should probably be like this:

2022/02/06 Opening Balance
    Equity:Starting Balances
    Assets:Paywave                   92.40

2) This program does not deal in currencies/commodities/etc. All it balances are numbers, what they mean is up to you. Since it doesn't understand the significance of "$" the parser assumes that it's part of the account name. So you have an account called "Assets:Paywave $92.40"

As to your questions:

porjo commented 2 years ago

Thankyou for your reply - all makes sense. I've converted my CSV to have a single 'Amount' field using whichever of Credit or Debit is present, and that seems to work well.

One suggestion for improvement would be to add to the File format page a comment about how this program's file format differs from the original Ledger (i.e. www.ledger-cli.org).