Virtual postings from python

61 views
Skip to first unread message

Ryan Nowakowski

unread,
Jul 24, 2022, 4:26:06 PM7/24/22
to Ledger
Hey Folks,

When I do a ledger.read_journal in python on a file with virtual postings,
has_flag(POST_VIRTUAL) returns False. I would expect it to return True.
Here's a bash run with the details:

$ ledger --version
Ledger 3.2.1-20200518, the command-line accounting tool

Copyright (c) 2003-2019, John Wiegley. All rights reserved.

This program is made available under the terms of the BSD Public License.
See LICENSE file included with the distribution for details and disclaimer.

$ python3 --version
Python 3.9.2

$ cat journal.dat
2022-7-24 August 2022 Budget
[Budget:Expenses:Gas] $200.00
[Budget:Equity] -$200.00

$ cat virtual_posts.py
import ledger

for xact in ledger.read_journal("journal.dat"):
print(repr(xact))
for post in xact.posts():
is_virtual = post.xdata().has_flags(ledger.POST_VIRTUAL)
must_balance = post.xdata().has_flags(ledger.POST_MUST_BALANCE)
print("%r is virtual: %s, must balance: %s" % (post, is_virtual, must_balance))

$ python3 virtual_posts.py journal.dat
<ledger.Transaction object at 0x7f588b011040>
<ledger.Posting object at 0x7f588b0110a0> is virtual: False, must balance: False
<ledger.Posting object at 0x7f588b011100> is virtual: False, must balance: False


Can anyone spot any issues with what I'm doing? If not, should I file a
bug against ledger?

Thanks!

Ryan N

Martin Michlmayr

unread,
Dec 27, 2022, 12:58:09 AM12/27/22
to ledge...@googlegroups.com, Alexis Hildebrandt
Copying Alexis

* Ryan Nowakowski <tub...@fattuba.com> [2022-07-24 15:26]:
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "Ledger" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ledger-cli+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ledger-cli/20220724202603.GB32382%40fattuba.com.

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

Alexis

unread,
Dec 27, 2022, 11:13:05 AM12/27/22
to ledge...@googlegroups.com
Thanks for reaching out, Ryan,

at first glance this seems to be a valid issue as
`post.xdata().has_flags(ledger.POST_MUST_BALANCE)` returns `False`
when `post.must_balance()` returns `True`.
Using `post.must_balance()` might be a viable interim solution.

Unfortunately there is no `is_virtual()` function on the `Posting`
type and the exposed `has_flags` fails with the following error for me:

```
did not match C++ signature:
has_flags(supports_flags<unsigned char, unsigned char> {lvalue}, unsigned char)
```

It would be greatly appreciated if you could file a bug against
ledger for this.


Best
Alexis

Ryan Nowakowski

unread,
Jan 16, 2023, 6:48:36 PM1/16/23
to ledge...@googlegroups.com
On 12/27/22 10:13 AM, Alexis wrote:

> Thanks for reaching out, Ryan,

Yup!  No prob.


> It would be greatly appreciated if you could file a bug against
> ledger for this.
Done: https://github.com/ledger/ledger/issues/2169
Reply all
Reply to author
Forward
0 new messages