reubano / csv2ofx

A Python library and command line tool for converting csv to ofx and qif files
MIT License
199 stars 113 forks source link

Possible to extract fees from the same line? #12

Closed mstenta closed 7 years ago

mstenta commented 8 years ago

CSVs exported from PayPay and Stripe contain two separate columns for the amount: one for the full amount of the transaction, and a second for the fee that Paypal/Stripe collects. Is it possible to use csv2ofx to separate these two amounts so that they can both be accounted for in the OFX?

reubano commented 8 years ago

Check out the customization section. You can make a mapping similar to the following:

mapping = {
    'amount': lambda r: r['full_amount'] + r['fee'],
    ...
}
mstenta commented 8 years ago

Oh ok - that's what I wasn't sure of. I saw that in the customization section, but didn't quite understand what to expect from it.

Will it create two transactions in the OFX? Or a split transaction that keeps the amount and fee separate?

reubano commented 8 years ago

The above mapping is one transaction. I also think I misunderstood your question initially. Your situation is more suited to split transactions like xero and it's associated mapping file. The difference is that your information is stored in multiple columns instead of multiple lines.

You have two options. The first is preprocess your csv file to create splits and make it look more like xero's (check out meza for a lib that can help with that). The other option is to use two mapping files and process your csv file twice. Something like this:

from operator import itemgetter

amount_mapping = {
    'has_header': True,
    'is_split': False,
    'account': 'Sales',
    'id': itemgetter('id'),
    'desc': itemgetter('description'),
    'amount': itemgetter('full_amount'),
    ...
}

fee_mapping = {
    'has_header': True,
    'is_split': False,
    'account': 'Fees',
    'id': itemgetter('id'),
    'desc': itemgetter('description'),
    'payee': 'Stripe'
    'amount': itemgetter('fee'),
    ...
}

I would recommend the first option since it will keep all information in one transaction. But the second may be easier to implement and worth doing if you don't care about doing it the "proper accounting" way via splits.

mstenta commented 8 years ago

Thanks @reubano - I'll play around with it.

It's unfortunate that the CSV exports offered by both PayPal and Stripe include the fees and the total amount in the same line (and they don't provide straight OFX exports). Makes it difficult to work with them without more complicated pre-processing.

reubano commented 7 years ago

I'll assume my recommendation above addressed your issue. Feel free to reopen if it didn't.