Handling reverted transactions in a CVS importer

60 views
Skip to first unread message

Vlad Dogaru

unread,
Sep 19, 2024, 10:20:12 AM9/19/24
to Beancount
Hi everyone,

Short version: How does one handle reverted transactions?  They have their own line in my CSV, listing -2 CHF, but the status is REVERTED.

Longer version, to potentially avoid an XY problem:

I'm very new to beancount and set about writing an importer for Revolut based on beangulp's csvbase (which IIUC is the newer way to do it).  I found an older thread on the list, but it seems that the csv header has changed since then, and it uses the older beancount.ingest.  I also like building things on my own, I suppose that's no surprise around here :)

I got the basics working, but I wonder how to handle reverted transactions.  Google is not super helpful, so maybe Revolut is using the wrong word for this, but AFAICT it's tiny transactions that merchants do to figure out the card is legit:

Type,Product,Started Date,Completed Date,Description,Amount,Fee,Currency,State,Balance
CARD_PAYMENT,Current,2023-09-09 20:35:29,,Google,-2.00,0.00,CHF,REVERTED,

I have a few ideas, but I wonder if this isn't already a solved problem:

1. Use `grep -v` (or awk, if we're being extra careful) to filter out these lines prior to importing.  But I'd like to see if I can do this entirely with beancount

2. Override `finalize`, check the `State` column, and add a posting of (-value) to reverted transactions.  This works, but I don't like that it pollutes the ledger.  I also don't like that these reverted lines have an empty `Balance` cell, which means I can't use csvbase's nifty automatic balance handling.

3. Is it possible to add a `skip_line` customization point to the csvbase importer?  This would allow configuring my importer to skip reverted lines, while keeping the balance handling (because lines will be skipped before attempting to fetch the balance column).  If you think that's a sensible approach I'm happy to take a stab at contributing a patch.

Thanks in advance,
Vlad

Red S

unread,
Sep 19, 2024, 2:29:24 PM9/19/24
to Beancount

You could patch basic csv importer, but I find that frequently used importers outgrow that pretty quickly on many other small requirements like this. Writing your own importer can be a good idea if you find that happening. Red’s importers has this. Here’s an example.

Vlad Dogaru

unread,
Sep 20, 2024, 2:42:36 AM9/20/24
to bean...@googlegroups.com
Thanks, that looks like what I need. In fact, your whole repo seems
extremely useful.

Cheers,
Vlad
> --
> You received this message because you are subscribed to a topic in the Google Groups "Beancount" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/beancount/jnAZSnzm1Ts/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to beancount+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/3b14aa08-0456-471e-bd6f-a3074392c543n%40googlegroups.com.

Red S

unread,
Sep 20, 2024, 4:01:54 AM9/20/24
to Beancount

Glad to hear! If you haven’t seen them already, some of these articles might save you time too.


Reply all
Reply to author
Forward
0 new messages