Method to convert posting accounts in already imported data?

Visto 61 veces
Saltar al primer mensaje no leído

Tim Legg

no leída,
10 ene 2023, 17:39:5110/1/23
a Beancount
Hi all, I have several years of data already imported into beancount and now I'm attempting to categorize some of the postings.

I have transactions like

2008-04-25 * "#AMAZON.COM" ""
Liabilities:BofA:PlatinumPlus -14.36 USD
Expenses:Buckets:Unaccounted 14.36 USD

I would like to script up something to go through all transactions where payee is ~ 'amazon' and change the Unaccounted to something else.

I have attempted to script something like:

    entries, errors, options = loader.load_file(input_file )

    for entry in entries:
        # Logic to check accounts / change postings
        printer.print_entry(entry)

    # printer.print_entries(options)

But the resulting bean file seems to be missing some things, like options, and I'm not sure what else, bean-check is showing unused pad entries after running the script. Anyway I wondered if there's already a script or process to do this already?

Martin Michlmayr

no leída,
10 ene 2023, 19:49:5010/1/23
a bean...@googlegroups.com
* Tim Legg <tim...@gmail.com> [2023-01-09 11:44]:
> 2008-04-25 * "#AMAZON.COM" ""
> Liabilities:BofA:PlatinumPlus -14.36 USD
> Expenses:Buckets:Unaccounted 14.36 USD
>
> I would like to script up something to go through all transactions where
> payee is ~ 'amazon' and change the Unaccounted to something else.

I haven't looked at it yet but check out the emails about
"autobean.refactor" from October 2022 on this mailing list.
You should be able to fix up your file with autobean.refactor.

--
Martin Michlmayr
https://www.cyrius.com/

Ben Blount

no leída,
10 ene 2023, 20:44:5510/1/23
a bean...@googlegroups.com
I haven't gotten a chance to try autobean.refactor yet and it's probably the best tool here. Just in case it doesn't work for whatever reason, there's an older attempt at this functionality that jbms did called JournalEditor. Here's an example of using it to rename accounts. I've used it for various jobs and it has worked well for me.

--
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/Y74HnY/7NDMacE%2BL%40jirafa.cyrius.com.

Tim Legg

no leída,
10 ene 2023, 20:48:4210/1/23
a Beancount
Cool thanks, I'll check that out.

For future reference for anyone who needs it.. I realized a few things after posting this. I had the same errors regarding unused pad entries when I ran 'bean-report main.bean print' I realized that my script and bean-report were both explicitly printing out the 'P' padded entries as well as the PAD directives. Also bean-report doesn't seem to print out the options.. so in short, this script probably would work if you go back and delete the PAD directives and add the options back.

But, I also realized I could accomplish what I wanted by implementing a plugin which transforms the transactions while reading/parsing the bean files. This actually is maybe preferable for me while I find out how I want to categorize everything as it seems to be non destructive.. it does not modify the bean files. I probably will reach a point I want to 'snapshot' everything and will then use bean-report to export a new bean file and then remove the plugin.

Red S

no leída,
10 ene 2023, 21:51:1210/1/23
a Beancount
This might not be apparent, but "snapshotting everything" might not work the way you expect: beancount isn't designed to print out just what it read plus a few changes to postings. Instead, it will print out interpolated, transformed, plugin-processed output, which might not be what you want.

On the other hand, autobean.refactor, as suggested here, is designed to do exactly what you seek. I don't have personal experience on how mature it is yet though.

Archimedes Smith

no leída,
11 ene 2023, 16:48:1611/1/23
a Beancount
Hi, unlikely others here I have lots of personal experience with `autobean.refactor` as its author. This is definitely one of the target use case of `autobean.refactor` and I'm happy to help if there is any issue. Note that it's now extracted to a separate repository (https://github.com/SEIAROTg/autobean-refactor) so you'll need to install from there.

> But, I also realized I could accomplish what I wanted by implementing a plugin which transforms the transactions while reading/parsing the bean files. This actually is maybe preferable for me while I find out how I want to categorize everything as it seems to be non destructive.. it does not modify the bean files. I probably will reach a point I want to 'snapshot' everything and will then use bean-report to export a new bean file and then remove the plugin.

If the only problem is pad, it's fairly easy because pad is merely a built-in plugin (https://github.com/beancount/beancount/blob/44cb769dc7828734a9251b6a77a43101590c19f1/beancount/loader.py#L45), which can be disabled with `option "plugin_processing_mode" "raw"`.

Sadly, a universal solution is not possible with a beancount plugin because processing already happens before even the first plugin was invoked: options are turned into a dict, includes are flattened, entries are sorted, total prices are converted to unit prices, pushtag / poptag / pushmeta / popmeta are applied, comments and spacing are dropped, and more. To make the process truly lossless a different parser will be needed, which is exactly why I made `autobean.refactor`.
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos