transfer_lots Plugin "locks" lots

76 views
Skip to first unread message

Peter

unread,
Nov 11, 2022, 10:19:20 AM11/11/22
to Beancount
Hi,

I'm using the transfer_lots plugin to transfer lots between accounts.

Sadly, after one transfer the lot seems to be locked. I.e., the `failed to categorize posting` error occurs.
See this MWE:

option "booking_method" "FIFO"
option "operating_currency" "USD"
plugin "beancount.plugins.auto_accounts"

option "insert_pythonpath" "True"
plugin "Plugins.transfer_lots" "transfer"
plugin "beancount.plugins.implicit_prices"

2021-01-08 * "" "Buy LOT"
Assets:Broker:LOT 1.25 LOT { 600 USD }
Equity:Opening-Account

2021-01-10 * "" "Transfer LOT" #transfer
Assets:Broker:LOT -1.25 LOT {}
Assets:Storage:LOT


2021-03-11 * "Buy more LOT"
Assets:Broker:LOT 0.25 LOT { 800 USD }
Equity:Opening-Account

2021-03-12 * "Transfer LOT" #transfer ; failed to categorize posting
Assets:Storage:LOT -1.25 LOT {}
Assets:Storage2:LOT

2021-04-10 * "Transfer LOT" #transfer
Assets:Broker:LOT -0.25 LOT {}
Assets:Storage2:LOT

2021-04-10 * "Transfer LOT" #transfer ; failed to categorize posting
Assets:Storage2:LOT -0.25 LOT {}
Assets:Storage:LOT

Why is that and what can I do here, to make this work?

Editing the last txn to: (inspired by github issue 541)

2021-04-10 * "Transfer LOT" #transfer ; failed to categorize posting
Assets:Storage2:LOT -0.25 LOT {USD}
Assets:Storage:LOT 0

Doesn't work, either:

** Balances before transaction --------------------------------

  Assets:Storage2:LOT                     0.25 LOT {800 USD, 2021-03-11}

  Assets:Storage:LOT                      1.25 LOT {600 USD, 2021-01-08}


** Unbooked Transaction --------------------------------

2021-04-10 * "Transfer LOT" #transfer
  Assets:Storage2:LOT                            -0.25 LOT {}     ;                                          
  Assets:Storage:LOT   0 <class 'beancount.core.number.MISSING'>  ; 0 <class 'beancount.core.number.MISSING'>


** Transaction --------------------------------

2021-04-10 * "Transfer LOT" #transfer
  Assets:Storage2:LOT  -0.25 LOT {-0 USD, 2021-04-10}  ;  0 USD
  Assets:Storage:LOT    0.25 LOT {-0 USD, 2021-04-10}  ; -0 USD


** Residual and Tolerances --------------------------------



** Balances after transaction --------------------------------

  Assets:Storage2:LOT                     0.25 LOT {800 USD, 2021-03-11}
* Assets:Storage2:LOT                     -0.25 LOT {-0 USD, 2021-04-10}

  Assets:Storage:LOT                      1.25 LOT {600 USD, 2021-01-08}
* Assets:Storage:LOT                       0.25 LOT {-0 USD, 2021-04-10}


Any help/input is greatly appreciated. How can I "unlock" the lots and transfer them more than once?

Regards

Ben Blount

unread,
Nov 11, 2022, 4:14:33 PM11/11/22
to bean...@googlegroups.com
This should probably be a FAQ.
See recent thread: https://groups.google.com/g/beancount/c/88WjwEhJKUk
and many before.

In short: Booking runs before plugins. There's been discussion in the past about having pre-booking plugins, it would certainly be helpful in a case like this.


--
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/5785792c-695a-4c5c-94d2-3adcc090aed7n%40googlegroups.com.

Peter

unread,
Nov 12, 2022, 4:06:28 AM11/12/22
to Beancount
Hi,

thanks for the answer. So, „there's no hope“ here until v3 (if it includes pre-booking plugins)?

Ben Blount

unread,
Nov 12, 2022, 11:34:19 AM11/12/22
to bean...@googlegroups.com
Yes. This is a flaw of the plugin approach to solving this problem - I recommend you deploy one of the other solutions from prior threads on this list about transferring lots between accounts. I am personally a fan of the bean-doctor integration of the beancount emacs plugin for this task.

Peter

unread,
Nov 13, 2022, 4:16:03 PM11/13/22
to Beancount
I looked through some threats I could find, but I didn't find any (automatic) solution to this problem, actually.

- the plugin posted in my initial posting doesn't work
https://github.com/hoostus/beancount-asset-transfer-plugin doesn't work (only supports LIFO and has errors)

I guess, I found your emacs plugin solution, but as I don't know or use emacs, I can't use it. I guessing it does (semi-automated):
- check bean-doctor
- take the lots
- convert them to postings
- replace the original txn

While this works, and I tried something like this manually, this has one huge disadvantage for me:
It replaces a "simple"
2021-01-10 * "" "Transfer LOT" #transfer
Assets:Broker:LOT -1.25 LOT {}
Assets:Storage:LOT
with a hard coded lot
2021-01-10 * "" "Transfer LOT" #transfer
Assets:Broker:LOT -1.25 LOT {600 USD, 2021-01-08}

Assets:Storage:LOT 1.25 LOT {600 USD, 2021-01-08}


I'm trying to import dozens to hundreds of transactions from different sources. Therefore, I can't/want to replace the reductions with hard coded lots, as there might be other lots coming in later that have to be used.

(Just throwing in all txns doesn't really work, too, as they are sorted by account, then by date. So, I wouldn't know if I'm skipping a txn. I tried to use bean-report print, but it erases txns with errors, which isn't helping.)

I'm lost at this point. 


Ben Blount

unread,
Nov 13, 2022, 8:04:00 PM11/13/22
to bean...@googlegroups.com
I agree with your analysis. Honestly the easiest way before+if this is officially supported may be to hack the beancount source and so it rewrites the lots before booking. Start here: https://github.com/beancount/beancount/blob/3ec62d4d8e68f352156eec6c7068b8aee8fc65f1/beancount/loader.py#L531 and add your code right before booking. Simply running the transfer_lots plugin manually before booking is called may just work without any other changes.

For hacking a python project `pip install -e` is great. You'll need to make sure to use the same modified package for fava etc too.

Reply all
Reply to author
Forward
0 new messages