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

aliases from included files are not applied in including files #1007

Open
mildred opened this issue Apr 10, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@mildred
Copy link

commented Apr 10, 2019

I'm playing with account hierarchy to learn accounting, and I noticed that aliases defined in a ledger file included in a global file are not applied to the global file. I'm using the following file structure:

global.ledger file:

#!/usr/bin/env hledger-exec

include accounts.ledger

# Following are the transactions
...

accounts.ledger file contains the account hierarchy with its aliases:

account financial accounts:banks:main bank account  ; type:Asset no:512
alias bank=financial accounts:banks:main bank account
alias a512=financial accounts:banks:main bank account
...

account expenses:buying ; type:Expense no:60
alias a60=expenses:buying
...

account revenue:products sold ; type:Revenue no:70
alias a70=revenue:products sold
...

I'm using this hierarchy because when running hledger-web or hledger-ui from the main files, new transactions made from the UI are appended to the main file. However, I want the account hierarchy to be separate, simply because I might modify it while I'm using hledger-web or ui at the same time.

When I declare aliases in accounts.ledger, they are not used in the global file. I have to declare them in the global file for them to be understood.

The fact that aliases are not propagated to including files is not in the documentation.

Perhaps the documentation should be updated, and perhaps aliases should be allowed to span to including files. having them restricted to the files they are in is also understandable, but perhaps use case around this should be discussed more.

@simonmichael

This comment has been minimized.

Copy link
Owner

commented Apr 10, 2019

'Tis mentioned a bit, at https://hledger.org/manual.html#basic-aliases, and particularly at https://hledger.org/manual.html#directives - see the notes there. Basically alias and some other directives are designed to last only until the end of the current file.

I see how this can be surprising/unsatisfying. I often find it annoying myself. Why does it work this way? It's to preserve these properties, which I think are worthwhile:

  1. reordering files does not change their meaning
  2. adding a file does not change the meaning of the other files

As a practical matter for right now,

@ony

This comment has been minimized.

Copy link
Collaborator

commented Apr 13, 2019

Aliases actually propagated to included files. Since migration to hledger I changed my layout to something like:

# effective-hledger.dat

commodity $                
    ; note American Dollars    
    format $1,000,000,000.00          

alias tips=Expenses:Tips

include ledger-2009.dat
# ...
include ledger-2019.journal

Though it is only chain and I cannot have anymore currencies/accounts/aliases split in different files it works for me.

I guess this is come-back of #510 . Maybe it worth to consider export include accounts.ledger syntax or something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.