Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with generated accounts in Automated Transactions #2350

Closed
igbanam opened this issue Jun 18, 2024 · 3 comments
Closed

Issue with generated accounts in Automated Transactions #2350

igbanam opened this issue Jun 18, 2024 · 3 comments

Comments

@igbanam
Copy link
Contributor

igbanam commented Jun 18, 2024

tl;dr

When an automated transaction uses a complex query to specify the rule, if a new account gets introduced in that rule, this account is omitted from the balance report.

long form

Consider this simple transaction

2024-06-18 * Payee
    Expenses    42 EUR
    Assets:Checking

A simple balance query shows

  -42 EUR  Assets:Checking
   42 EUR  Expenses
---------
        0

Now, let's assume this purchase is from a store which has the VAT baked in; but we want to know how much VAT we pay per purchase. A simple rule for an automated transaction would look like

= ^Expenses
    Expenses:Tax:VAT  0.13
    $account  -0.13

Our balance query now yields

  -42 EUR  Assets:Checking
   42 EUR  Expenses
    5 EUR    Tax:VAT
---------
        0

This makes sense… until we want to target VAT to certain postings. The ^Expenses rule no longer works. We would need some complex query to properly target these postings. One way I thought of doing this is using tags. Our ledger now becomes…

= %/vat/
    Expenses:Tax:VAT  0.13
    $account  -0.13

2024-06-18 * Payee ; :vat:
    Expenses    42 EUR
    Assets:Checking

Note the tag is on the payee line

With this, the balance query looks like

  -42 EUR  Assets:Checking
   42 EUR  Expenses
---------
        0

…no sign of the Expenses:Tax:VAT account.

When I shift the tag into the posting, like so

= %/vat/
    Expenses:Tax:VAT  0.13
    $account  -0.13

2024-06-18 * Payee
    ; :vat:
    Expenses    42 EUR
    Assets:Checking

Note the posting is now applies to the Expenses directly. The balance query now reports

  -37 EUR  Assets:Checking
   37 EUR  Expenses
---------
        0

This is what I expect — 5 EUR out of this should be in Expenses:Tax:VAT — but there's no Expenses:Tax:VAT listed in the balance report.

When I try to switch out = %/vat/ for = expr has_tag("vat"), = expr has_tag(/vat/), or any other expression which isn't the short form, I get

While parsing file "/path/to/auto-tags.ledger", line 1:
While parsing value expression:
  has_tag("vat"

While parsing automated transaction:
> = expr has_tag("vat")
Error: Invalid token '<end of input>' (wanted ')')
@tbm
Copy link
Contributor

tbm commented Jun 18, 2024

You write:

…no sign of the Expenses:Tax:VAT account.

But this is not true. Your:

= %/vat/
    Expenses:Tax:VAT  0.13
    $account  -0.13

works just fine. You can verify this by running ledger reg :vat. The reason the balance report doesn't show it is because Expenses:Tax:VAT is applied to both postings, so it becomes 0.

Although you say:

  -42 EUR  Assets:Checking
   42 EUR  Expenses

I see:

             -37 EUR  Assets:Checking
              37 EUR  Expenses

which makes sense because the 0.13 is applied to both accounts.

In any case, you need to filter on both the tag and the account name.

You can do this with:

= expr 'has_tag("vat") and account =~ /^Expenses/'
    Expenses:Tax:VAT  0.13
    $account  -0.13

The '...' quotes are only needed to avoid the Invalid token error you already mention. That's a parsing issue (see #872).

@igbanam
Copy link
Contributor Author

igbanam commented Jun 18, 2024

The reason the balance report doesn't show it is because Expenses:Tax:VAT is applied to both postings, so it becomes 0.

This ☝🏽 tracks!

Thanks for clarifying. From the docs, I didn't know the argument to expr had to be a string.

@igbanam igbanam closed this as completed Jun 18, 2024
@tbm
Copy link
Contributor

tbm commented Jun 18, 2024

From the docs, I didn't know the argument to expr had to be a string.

I'm not sure what you mean, but if you mean that it needs expr: actually, I just tried, the following works and is even easier:

= %/vat/ and ^Expenses
    Expenses:Tax:VAT  0.13
    $account  -0.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants