How to automatically close all descendants of an account?

70 views
Skip to first unread message

cantas...@gmail.com

unread,
Aug 21, 2022, 3:59:05 PM8/21/22
to Beancount
Hello,
Sorry if this question has already been asked in the past. I was not able to find any references.

Is there a way to automatically close all an account and all its descendants? It'd be useful for investment accounts with lots of commodities. Maybe there's already a plugin that I am not aware of.

Thank you,
Stefano

Martin Blais

unread,
Aug 21, 2022, 5:28:18 PM8/21/22
to Beancount
That's a good idea. I would certainly use it.
The answer is there isn't at the moment.

--
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/4ae041c8-9586-4987-bf01-03e3ce29c325n%40googlegroups.com.

Red S

unread,
Aug 22, 2022, 4:57:41 AM8/22/22
to Beancount
I've wanted one too. Just wrote it up. See here.

In short:

pip3 install git+https://github.com/redstreet/beancount_reds_plugins

And add this to your sources:

plugin "beancount_reds_plugins.autoclose_tree.autoclose_tree" "{}"

Stefano Mihai Canta

unread,
Aug 22, 2022, 9:18:59 AM8/22/22
to bean...@googlegroups.com
Hey,
Thank you! I was going to write my first plugin, but you beat me to it :)
I'll use this as a template for the future.

I appreciate it,
Stefano

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/mTDZ3sQjH9U/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/25689f47-27c2-4cc2-958c-397a468846d1n%40googlegroups.com.

Stefano Mihai Canta

unread,
Aug 22, 2022, 9:27:22 AM8/22/22
to bean...@googlegroups.com
There might be a problem with the account name matching.
This directive:
2018-11-10 close Liabilities:Credit-Cards:Wife:Citi
also seems to match an account named Liabilities:Credit-Cards:Wife:Citi-CustomCash, which should remain open. Instead, the directive should match Liabilities:Credit-Cards:Wife:Citi and Liabilities:Credit-Cards:Wife:Citi:*, but not Liabilities:Credit-Cards:Wife:Citi*.

Stefano

Red S

unread,
Aug 22, 2022, 3:22:48 PM8/22/22
to Beancount
There might be a problem with the account name matching.
This directive:
2018-11-10 close Liabilities:Credit-Cards:Wife:Citi
also seems to match an account named Liabilities:Credit-Cards:Wife:Citi-CustomCash, which should remain open. Instead, the directive should match Liabilities:Credit-Cards:Wife:Citi and Liabilities:Credit-Cards:Wife:Citi:*, but not Liabilities:Credit-Cards:Wife:Citi*.

Indeed, fixed now.


Thank you! I was going to write my first plugin, but you beat me to it :)
I'll use this as a template for the future.

Welcome! But oops, didn't mean to take away that opportunity. The more plugin writers we have, the better :). Glad it helps as a template at least.

 

Red S

unread,
Aug 22, 2022, 3:25:35 PM8/22/22
to Beancount
Feel free to let me know of other bugs, or better yet, send pull requests on github if you're up for it.

Daniele Nicolodi

unread,
Aug 22, 2022, 3:29:04 PM8/22/22
to bean...@googlegroups.com
On 22/08/2022 10:57, Red S wrote:
> I've wanted one too. Just wrote it up. See here
> <https://github.com/redstreet/beancount_reds_plugins/tree/main/beancount_reds_plugins/autoclose_tree#readme>.
>
> In short:
>
> pip3 install git+https://github.com/redstreet/beancount_reds_plugins
>
> And add this to your sources:
>
> plugin "beancount_reds_plugins.autoclose_tree.autoclose_tree" "{}"

Is there a reason why you pass an "empty" configuration string to a
plugin that does not need any configuration?

Cheers,
Dan

Red S

unread,
Aug 22, 2022, 3:48:30 PM8/22/22
to Beancount
> plugin "beancount_reds_plugins.autoclose_tree.autoclose_tree" "{}"

Is there a reason why you pass an "empty" configuration string to a
plugin that does not need any configuration?

It's a holdover from when I originally had a config option that I simplified out, but wasn't committed to removing fully yet. Now removed

Stefano Mihai Canta

unread,
Aug 22, 2022, 4:09:01 PM8/22/22
to bean...@googlegroups.com
Does the order of the directives matter?

Here's what I have (simplified)

plugin "beancount_reds_plugins.autoclose_tree.autoclose_tree"
plugin "beancount.plugins.auto_accounts"
2017-08-10 open Assets:Investments:Non-Retirement:Ciara:Robinhood
2017-11-13 close Assets:Investments:Non-Retirement:Ciara:Robinhood
[... a bunch of transactions into subaccounts, :SIRI, :Cash, etc]

I don't see a close directive for Assets:Investments:Non-Retirement:Ciara:Robinhood:SIRI in Fava.

--
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/mTDZ3sQjH9U/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/e4e7c5e2-edee-4a9e-b75b-6564bbf90279n%40googlegroups.com.

Red S

unread,
Aug 22, 2022, 4:17:06 PM8/22/22
to Beancount
I don't know -- I don't use the auto_accounts plugin. I assume it inserts open directives, meaning autoclose_tree should likely come after it. Could you please try and confirm, and I'll update the doc.

Stefano Mihai Canta

unread,
Aug 22, 2022, 4:35:44 PM8/22/22
to bean...@googlegroups.com
That was it. Swapping the order of the two plugins fixed the error. In addition, auto_accounts opens the leaves automatically, but it does not add a directive to open an ancestor account if that's missing. I had another set of transactions with a different broker, and all the leaf accounts had an open statement, but not the parent one (...:WiseBanyan was never open, but ...:WiseBanyan:Cash, ...:WiseBanyan:APPL, etc were).


--
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/mTDZ3sQjH9U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beancount+...@googlegroups.com.

Red S

unread,
Aug 22, 2022, 6:33:23 PM8/22/22
to Beancount
That was it. Swapping the order of the two plugins fixed the error. In addition, auto_accounts opens the leaves automatically, but it does not add a directive to open an ancestor account if that's missing. I had another set of transactions with a different broker, and all the leaf accounts had an open statement, but not the parent one (...:WiseBanyan was never open, but ...:WiseBanyan:Cash, ...:WiseBanyan:APPL, etc were).

Yeah, I ran into that case as well. autoclose_tree now handles it.

You can close unopened parents:

2017-11-10 open Assets:Brokerage:AAPL
2017-11-10 open Assets:Brokerage:ORNG
2018-11-10 close Assets:Brokerage ; this account was never opened, and this would
                                  ; normally be an invalid directive

becomes:

2017-11-10 open Assets:Brokerage:AAPL
2017-11-10 open Assets:Brokerage:ORNG
2018-11-10 close Assets:Brokerage:AAPL
2018-11-10 close Assets:Brokerage:ORNG


 

Red S

unread,
Aug 22, 2022, 8:39:32 PM8/22/22
to Beancount
On Monday, August 22, 2022 at 3:33:23 PM UTC-7 Red S wrote:
That was it. Swapping the order of the two plugins fixed the error.

Documented in README.md

Stefano Mihai Canta

unread,
Aug 22, 2022, 9:30:51 PM8/22/22
to bean...@googlegroups.com
Hi,
I still get this error message in fava with your latest change if I get rid of the open directive, and rely on the auto_accounts plugin.
image.png
Thanks,


--
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/mTDZ3sQjH9U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beancount+...@googlegroups.com.

Red S

unread,
Aug 23, 2022, 12:03:47 AM8/23/22
to Beancount
Would you mind filing a bug in github with a minimal reproducible example? If you feel up to it, a fix with a unit test is also appreciated.

Red S

unread,
Aug 24, 2022, 7:36:37 PM8/24/22
to Beancount
Thanks for filing.

beancount.plugins.auto_accounts inserts an open for Expenses:Non-Retirement:Auto:Fit because it sees the close directive for it. The open and Close occur on the same date, leading to this error. Fixed by special casing this scenario.



Reply all
Reply to author
Forward
0 new messages