Skip to content

CSV report output does not represent account tree structure #1566

@benwebber

Description

@benwebber

I'm passing hledger's CSV reports through pandoc/LaTeX to generate attractive PDF reports.

I like how the tree view works in the text reports:

hledger bs -f sample.journal --tree --no-elide
Balance Sheet 2008-12-31

             || 2008-12-31 
=============++============
 Assets      ||            
-------------++------------
 assets      ||        $-1 
   bank      ||         $1 
     saving  ||         $1 
   cash      ||        $-2 
-------------++------------
             ||        $-1 
=============++============
 Liabilities ||            
-------------++------------
 liabilities ||        $-1 
   debts     ||        $-1 
-------------++------------
             ||        $-1 
=============++============
 Net:        ||          0 

However, the CSV output does not encode the tree structure:

hledger bs -f sample.journal --tree --no-elide -O csv
"Balance Sheet 2008-12-31",""
"Account","2008"
"Assets",""
"assets","$-1"
"bank","$1"
"saving","$1"
"cash","$-2"
"Total:","$-1"
"Liabilities",""
"liabilities","$-1"
"debts","$-1"
"Total:","$-1"
"Net:","0"

In the example above, one can't determine that assets:cash and assets:bank:saving belong to assets without prior knowledge of the account names and more complex parsing rules. It might be possible to work around the issue with aliases, but I haven't tested that yet.

I can think of two ways to encode the tree directly:

  1. Indent each account name with a number of spaces, as we do in the text output. For example:

    "assets","$-1"
    "  bank","$1"
    "    saving","$1"
    "  cash","$-2"
    
  2. Add another column representing the depth.

Technically, either would be a breaking change. However, given that there is no difference between the tree output and the normal output, there is no real reason to generate a CSV report with --tree right now. I can't imagine either change would impact many users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-WISHSome kind of improvement request or proposal.csvThe csv file format, csv output format, or generally CSV-related.regressionA backwards step, indicating a weakness in our QA. We don't like these.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions