Retroactively apply changes made in Importeer

111 views
Skip to first unread message

Mark

unread,
Aug 17, 2020, 4:15:01 PM8/17/20
to Beancount
Hi, all

I am wondering if there is a convenient way to retroactively apply changes made in Importers to current beancount journal. For example, if I created a new category
for certain transaction in an Importer, I would like to also change categories of all the previous transactions in the journal. 

One solution (hack) I can imagine could be this:
1. set up a temporary Importer
2. use `bean-extract -e my_journal.bean ... ` and map the change
    over entries that should be modified in `existing_entries` defined
    in `def extract(self, file, existing_entires=None)`. Return `existing_entries`. 
3. Uncomment all the lines in the output

Thanks ahead, and thanks for Martin for this amazing software!


Martin Blais

unread,
Aug 19, 2020, 11:21:37 PM8/19/20
to Beancount
No idea.
I keep all my imported sources in a repo but I hardly ever rerun on them.
If you keep you input file really neat you might be able to use a visual diff tool (e.g. xxdiff) and select the new bits you want.
More sophisticated than that you could write a script that attempts to map the new imported transactions to the original ones in the input and and replace.


--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/c9c8f157-2d4d-489f-bf2e-1a321ee33993n%40googlegroups.com.

Adam Wolenc

unread,
Sep 13, 2020, 10:20:33 AM9/13/20
to Beancount
This is exactly what I do in this situation. First I fix the importer and the testcases.
Then, separately, I create a mutation on the existing ledger to match it. Usually this involves some REGEX :)
Tips:
  Use source control (hg). This way you can a) see the diffs you've created , b) rewind to a good state if necessary
  Use Sublime or another editor that allows Find and Replace with multi-line regular expressions.

redst...@gmail.com

unread,
Sep 15, 2020, 2:07:00 PM9/15/20
to Beancount
Same here: I used to have a model where a subset of my beancount files were considered to be ephemeral, and could be regenerated from their sources any time. In practice, this means one can't make minor fixes or place comments. So this didn't work well.

I instead do what Martin and Adam posted above. In addition, I have a well developed set of scripts to quickly rename/reparent accounts and a few other things, and rely on my editor features to do anything more complex.

Ben Blount

unread,
Sep 15, 2020, 2:26:48 PM9/15/20
to bean...@googlegroups.com
Are your renaming / reparenting scripts published anywhere? I currently use perl oneliners, but it can be tedious for certain kinds of refactorings.

There's a beancount-aware renamer here that I haven't tried out yet, but it looks powerful.

redst...@gmail.com

unread,
Sep 15, 2020, 3:25:41 PM9/15/20
to Beancount
Mine are specific to my source tree, and are untested for the general case, so it wouldn't be a good idea to publish them :). But it's a rather simple 3 or 4 line bash script using "sed -i".
Reply all
Reply to author
Forward
0 new messages