Auto-posting based on commodity/currency not showing up in balance report?

From a post from Simon on the hledger google group, I thought I'd understood that I can make auto-postings based on commodities using cur:<commodity> (using the hledger query language). I've also included an example of an auto posting based on the account name.

= expr cur:GOOG
    (Allocation:Equities:World)                 *1.0

= expr ^Assets:Investments:Pension:
    (Assets:Virtual:NetPension)                 *0.8

2024-10-01 Test1
  Assets:Investments:Pension:Blah             = 60 GBP
  Equity:Opening-Balances

2024-10-01 Test2
  Assets:Investments:Stock:Blah               = 60 GOOG
  Equity:Opening-Balances

However, in the balance report I only see auto postings based on account name, not those based on commodity:

$ hledger bal --auto
              60 GBP  Assets:Investments:Pension:Blah
             60 GOOG  Assets:Investments:Stock:Blah
              48 GBP  Assets:Virtual:NetPension
             -60 GBP
            -60 GOOG  Equity:Opening-Balances
--------------------
              48 GBP  

Why is Assets:Virtual:NetPension there, but not Allocation:Equities:World?

1 Like

That’s using an expr keyword as in Ledger; in hledger it’s different (https://hledger.org/1.40/hledger.html#query-types > expr:) and not needed here.

1 Like

More details: to see what's happening more clearly, compare hledger print -x [--auto].

The second rule is working as-is (the expr word is treated as an OR'd account query and has no effect).

In the first rule, the expr word is the only account query, so it's acct:expr AND cur:GOOG, which matches nothing. When you remove the expr word, it then matches both GOOG postings so has no effect on the balance report. If you add a correct account query, it'll match just that posting:

= cur:GOOG assets
    (Allocation:Equities:World)                 *1.0
2 Likes