Heyho,
Thanks for beancount, it is an awesome piece of technology!
My situation: My root file "root.beancount" includes sub files for all my individual accounts, i.e "my_bank.beancount". What I'd like to do is run over all Transactions in "my_bank.beancount", potentially changing the Accounts in the postings of each Transaction and write it back out into the file it was read from - keeping the order of the entries in the file.
I tried this:
entries, _, _ = beancount.loader.load_file("root.beancount")
for e in entries:
if not os.path.basename(e.meta['filename']) == "my_bank.beancount":
continue
if isinstance(e, data.Transaction):
change_around_account(e)
printer.print_entry(e)
This does not work as expected:
- it changes whitespace: while all my postings used to be indented by four spaces, after running this they are only indented by 2.
- I have several "balance" and "note" statements in the file which get reordered and empty lines inserted before and after. I understand that this is insignificant for beancount, but the ordering is meaningful to me.
It is not too hard to parse out the individual pieces that I am interested in the files and iterate over the items myself that way, but I wondered if there was a blessed way of doing what I want.
Thanks,
Holger