egh / ledger-autosync

Synchronize your ledger-cli files with your bank.
GNU General Public License v3.0
273 stars 42 forks source link

PayPal CSV import gives `Exception: Cannot determine CSV type` #26

Closed 501st-alpha1 closed 6 years ago

501st-alpha1 commented 7 years ago

I tried to import a CSV file downloaded from my PayPal account (from this page), and I got this error:

Traceback (most recent call last):
  File "/usr/local/bin/ledger-autosync", line 11, in <module>
    load_entry_point('ledger-autosync==0.3.4', 'console_scripts', 'ledger-autosync')()
  File "build/bdist.linux-x86_64/egg/ledgerautosync/cli.py", line 239, in run
  File "build/bdist.linux-x86_64/egg/ledgerautosync/cli.py", line 133, in import_csv
  File "build/bdist.linux-x86_64/egg/ledgerautosync/sync.py", line 151, in parse_file
  File "build/bdist.linux-x86_64/egg/ledgerautosync/converter.py", line 407, in make_converter
Exception: Cannot determine CSV type

I looked at the CSV file, and this is the first line:

Date, Time, Time Zone, Name, Type, Status, Amount, Receipt ID, Balance, 

which I notice is different from this line in the codebase, so maybe PayPal changed their CSV format?

egh commented 7 years ago

The FIELDSET is a subset of all the CSV lines. The theory was that there might be some change in the CSV format but we could still import as long as we had the necessary fields.

It's still working for me, though, when I download from that page.

My CSV has the header:

Date, Time, Time Zone, Name, Type, Status, Currency, Gross, Fee, Net, From Email Address, To Email Address, Transaction ID, Counterparty Status, Shipping Address, Address Status, Item Title, Item ID, Shipping and Handling Amount, Insurance Amount, Sales Tax, Option 1 Name, Option 1 Value, Option 2 Name, Option 2 Value, Auction Site, Buyer ID, Item URL, Closing Date, Escrow Id, Invoice Id, Reference Txn ID, Invoice Number, Custom Number, Receipt ID, Balance, Contact Phone Number, 

which is slightly different from yours. It seems that paypal will only export a subset of all possible columns, which seem to be listed here: https://www.paypalobjects.com/webstatic/en_US/developer/docs/pdf/pp_merchantsetupadministrationguide.pdf

Can you provide me with a complete first line from the CSV so I can figure which fields I am using that you are missing to work around this? Thanks!

501st-alpha1 commented 7 years ago

The line I provided above was the complete first line. Did you mean you'd like a line of data too?

I noticed in the linked PDF on page 53 there is a screenshot showing a link Customize Download Fields. I don't see that link on that page when logged in to my PayPal account, all I see is Downloadable History Log Updates.

egh commented 7 years ago

@501st-alpha1 Sorry this dropped off my radar. Yes, if you could provide a sample of the kind of data you have and an idea of what kind of ledger posting you would expect from that data, that would be helpful.

501st-alpha1 commented 7 years ago

@egh No problem.

Here are the complete (but anonymized) first 3 lines of one of my downloaded CSV files:

Date, Time, Time Zone, Name, Type, Status, Amount, Receipt ID, Balance, 
"12/31/2016","23:59:59","PST","Some User","Payment Sent","Completed","-12.34","","0.00",
"12/31/2016","23:59:59","PST","Bank Account","Add Funds from a Bank Account","Completed","12.34","","12.34",

Those two transactions were created by sending a user $12.34 from the PayPal UI, using a bank account. I'd expect ledger-autosync to output something like this:

2016/12/31 PayPal
    Assets:Bank Account          $-12.34
    Assets:PayPal                 $12.34
    ;; csvid: someid
2016/12/31 Some User
    Assets:PayPal                $-12.34
    ;; csvid: someid
    Expenses:Unknown              $12.34
egh commented 7 years ago

@501st-alpha1 Thanks for the sample! I'll see what I can do.

501st-alpha1 commented 6 years ago

FYI, I noticed that PayPal recently launched a new activity downloader here, but the file generated is in the same format for me, so I'm still getting this error.

egh commented 6 years ago

@501st-alpha1 I have just pushed up a converter for this alternate (?) paypal CSV format. Also I fixed an issue with the byte order mark which has started to appear in my CSV downloads from paypal.

501st-alpha1 commented 6 years ago

Oops, in my last comment I was mistaken; the new file I downloaded additionally has the Currency field, though the value is only ever USD for me.

I got the same error again when I tried to sync the new file. If my file just has an extra column, it should still work, right? A possible cause for the error is that the new file has the header cells double-quoted, while the old one does not.

Old header (same as above):

Date, Time, Time Zone, Name, Type, Status, Amount, Receipt ID, Balance, 

New header:

"Date","Time","TimeZone","Name","Type","Status","Currency","Amount","Receipt ID","Balance"

The new converter works great for the previous files I downloaded though, so thanks!

egh commented 6 years ago

I believe this was a problem with the space in Time Zone and I have corrected the issue.

I am beginning to see the similarities between these 2 paypal formats, but they sure are pretty different on the service.

501st-alpha1 commented 6 years ago

Good catch, I missed that one too. This is now working for me, thanks!