Virtual postings from python

Skip to first unread message

Ryan Nowakowski

Jul 24, 2022, 4:26:06 PMJul 24
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
import ledger

for xact in ledger.read_journal("journal.dat"):
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 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?


Ryan N
Reply all
Reply to author
0 new messages