apauley / hledger-flow

An hledger/ledger-cli workflow focusing on automated statement import and classification
GNU General Public License v3.0
174 stars 21 forks source link

`hledger-flow` reports empty for user sub-accounts (due to missing `directives.journal` at lower levels) #112

Open stewmehr opened 1 year ago

stewmehr commented 1 year ago

Describe the bug I have set up an account structure with several users in my ./import directory (e.g. ./import/userA/bankX/checking/1-in, ./import/userB/bankY/checking/1-in, etc. ...). This works fine in terms of importing CSVs and generating journal files, but I am struggling with hledger-flow report. The generated ./reports directory looks as follows:

reports
├── all
│   └── 2023
│       ├── balance-sheet.txt
│       ├── income-expenses.txt
│       ├── monthly
│           └── income-expenses.txt
├── userA
│   └── 2023
│       ├── accounts.txt
│       ├── balance-sheet.txt
│       ├── income-expenses.txt
│       └── monthly
│           └── income-expenses.txt
└── userB
    └── 2023
        ├── accounts.txt
        ├── balance-sheet.txt
        ├── income-expenses.txt
        └── monthly
            └── income-expenses.txt

Unfortunately, only the reports in ./reports/all contain any numbers whereas the reports generated for userA and userB are empty. This is due to the fact that all my account info, including non-default account names and types, is stored in ./directives.journal in the top-level directory. By default, this directives file is only included in ./all-years.journal but not included in ./import/user{A,B}/all-years.journal. Thus, hledger does not know the correct mapping of my income and expense accounts and is unable to generate any income statements or balance sheets for individual user accounts.

This can easily be fixed by appending the line

include ../../directives.journal

to the respective all-years.journal files at lower levels. I am not sure if this is the most efficient solution but I cannot think of a better one right now.

Version and Runtime Information

Please mention the version number of hledger-flow you are using:

hledger-flow 0.15.0 darwin x86_64 ghc 9.2 4c5ba1281b33852c1fba1f2f01eb5d2d9921ded9

Is this the latest version? Yes Please confirm your issue using the latest version of hledger-flow, maybe it has already been fixed. No

Also include the runtime options of the command you ran, e.g:

$ hledger-flow report

To Reproduce

Issue cannot be reproduced with data available at https://github.com/apauley/hledger-flow-example as the repo's import directory contains only a single user directory.

Expected behavior

I would expect the reports in directories other than all not to be empty.

Desktop (please complete the following information):

apauley commented 1 year ago

Hi @stewmehr

The first line of those generated reports contain the hledger command that was used to generate the report.

What happens if you run that yourself, but add another --file parameter for the directives.journal, either before or after the current one? e.g. hledger --file directives.journal --file import/userA/all-years.journal <...>

Can you give an example of your directives.journal with "account info, including non-default account names and types" that would result in an empty report even when there are actual data in the userA and userB directories? Please also include some example user data, so that I can replicate it.

stewmehr commented 1 year ago

Hi @apauley

Thank you for your swift reply. I was not aware that it was possible to supply multiple --file args even though that does make a lot of sense. Adding the directives.journal this way leads to correct results which is a less intrusive way of fixing the issue than modifying any .journal files. Since the directives.journal is always created and empty by default, maybe it makes sense to add --file directives.journal to all report commands?

If you still want to investigate this, here are the first few lines of my directives.journal:

; journal created 2023-05-12 by hledger

account aktiva  ; type: A
account fremdkapital  ; type: L
account eigenkapital  ; type: E
account ertraege  ; type: R
account aufwendungen  ; type: X

account aktiva:userA:cash
account aktiva:userA:bankX:checking

account aktiva:userB:cash
account aktiva:userB:bankY:checking

I can try to clean some of my user data later today but it will take me a little more time to supply CSVs, rules files etc. It may be faster to replicate the issue by creating a copy of the gawie dir in the example repo and reassigning the account types there. The issue probably disappears if one uses default account names such as  assets:XXX:..., income:XXX:..., expenses:XXX:... etc. because those will be recognized even if no directives journal is supplied.

EDIT just to clarify: My (German) mapping of the default top-level accounts is

assets      --> aktiva
liabilities --> fremdkapital
equity      --> eigenkapital
income      --> ertraege
expenses    --> aufwendungen
bronislav commented 1 year ago

I have another issue due to the missing (not included) directives.journal file. I have a list of commodities defined there. As a result, some of the reports display them in different ways. Relevant section of my directives.journal:

commodity 1,000.00 CAD
commodity 1,000.00 USD
commodity 1,000.00 UAH

But the report generated without including directives.journal display totals differently:

870.45 CAD, UAH1,759.71

As discussed above, we must add directives.journal as input to all lower granularity reports.