[HOWTO] Register of virtual accounts related to a main account?

416 views
Skip to first unread message

François Beausoleil

unread,
Nov 22, 2015, 3:09:17 PM11/22/15
to Ledger
Hi all!

I'd like to list virtual accounts that are also named when I touch a real account:

2015-01-01 Payee
  Expenses:Food
  Assets:Bank    $ -100
  (food)    $ -100

2015-01-02 Payee 2
  Expenses:Cell
  Assets:Bank   $ -30
  (cell)    $ -30

# What I'd like to obtain:

$ ledger reg ...

cell  $ -30
food   $ -100

Using "ledger reg --related Assets:Bank" returns other postings against real accounts. --related-all adds more information, but I want the register of virtual postings.

How can I create such a report?

Thanks!
François

Alexis

unread,
Nov 23, 2015, 2:24:08 AM11/23/15
to ledge...@googlegroups.com
Hello François,
using the --limit virtual or --display virtual option should give
you the reports you want.

Search for --limit and --display in the "Commands & Options Index"
sectionš of the manual to find references for explanations and
examples of how they work.

The main difference being that --limit affects the running total being
shown, whereas --display doesn't.


Cheers,
Alexis

š http://ledger-cli.org/3.0/doc/ledger3.html#Commands-_0026-Options-Index

François Beausoleil

unread,
Nov 23, 2015, 9:21:09 AM11/23/15
to Ledger
Hello Alexis,

I'm having difficulty understanding how it works.

I found http://ledger-cli.org/3.0/doc/ledger3.html#Posting_002faccount-details which says "R1’ if a posting is not virtual, ‘0’ otherwise."

I tried ledger reg Assets:Bank --display 'R'

which returns the original postings, not the virtual ones. Using 'not R' returns nothing.

I'm certain I'm doing something silly: https://gist.github.com/francois/eae3ae92a66fcbf5315c

I also tried variations like 'R == 1' or 'R == false', returning either an error, an empty report or only the real accounts.

What would be the exact syntax I should use to return a register of only the virtual accounts?

Thank you very much!
François Beausoleil

Alexis

unread,
Nov 23, 2015, 10:16:26 AM11/23/15
to ledge...@googlegroups.com
Hello François,
> I'm certain I'm doing something silly:
> https://gist.github.com/francois/eae3ae92a66fcbf5315c

In your example you request all postings for the Asset:Bank account
which are virtual, yet there are none.
The virtual postings are the ones to the (cell) and (food) account.

If you wanted reg Assets:Bank --display virtual
to work you would need a posting similar to:
(Assets:Bank) € 123,45

> What would be the exact syntax I should use to return a register of only
> the virtual accounts?

% ledger -f a.txt reg --display virtual


Cheers,
Alexis

François Beausoleil

unread,
Nov 23, 2015, 10:44:12 AM11/23/15
to ledge...@googlegroups.com
Hi,
> % ledger -f a.txt reg —display virtual

Then I haven’t explained myself fully: I want virtual accounts that were touched in the same transaction as a posting that touches Assets:Bank.

If I were doing this in SQL:

SELECT account, amount
FROM postings
WHERE transaction_id IN (
SELECT transaction_id
FROM postings
WHERE account = ‘Assets:Bank’)
AND virtual

If a transaction touches Assets:Bank, display *all* virtual postings.

Is this possible using Ledger?

Thanks!
François

Alexis

unread,
Nov 23, 2015, 11:46:54 AM11/23/15
to ledge...@googlegroups.com
Hello François,
from my understanding Ledger has more of a filter than a query language,
and I'm uncertain how one do with ledger what you want to do.

Surely one could script it using the Ledger Python API, but with only
commandline options, I don't know.

Can someone else shed some light on the issue?


Cheers,
Alexis

Andrew Maffei

unread,
Dec 1, 2015, 9:01:32 PM12/1/15
to Ledger

Can someone else shed some light on the issue? 

I solve a similar problem by adopting a naming convention 

For example, at work I like to keep track of expenses on science grants I manage using 3 different account hierarchies. One hierarchy of account names is "real", the other two are virtual. 

One hierarchy represents the way my institution (WHOI) prints it's project balance sheets, another represents the way my funders (NSF) like to see expenses reported in annual reports, and the third is the way I (ANDY) think about the money I am spending and managing. So, when I run across a salary cost (for example) I post it something like this...

2015-01-01 Week 01 Payroll Distribution
    WHOI:Expenses:Salary    1000
    WHOI:Assets:Grant#2304982  -1000
    (NSF:Expenses:Personnel   1000)
    (ANDY:Expenses:PeopleCosts     1000)

ledger bal ^NSF:Expenses 

prints out all my expenses the way NSF likes to see them

Using a similar approach one could setup the above journal entries as follows:

2015-01-01 Payee
  Expenses:Food
  Assets:Bank    $ -100
  (V:food)    $ -100


2015-01-02 Payee 2
  Expenses:Cell
  Assets:Bank   $ -30
  (V:cell)    $ -30

and then "ledger reg --related Assets:Bank ^V:" would do the trick
 
Alexis
Reply all
Reply to author
Forward
0 new messages