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

/accounts API: returns only top-level accounts #985

Closed
real-dam opened this Issue Mar 9, 2019 · 4 comments

Comments

Projects
None yet
2 participants
@real-dam
Copy link

real-dam commented Mar 9, 2019

As seen in http://demo.hledger.org/accounts all accounts appear to have root as parent (_aparent field).

For example the record for Assets:Crypto:BTC looks like this:

{
  "anumpostings": 2,
  "aebalance": [
    {
      "aprice": {
        "tag": "NoPrice"
      },
      "aquantity": {
        "decimalMantissa": 13,
        "decimalPlaces": 0
      },
      "acommodity": "",
      "aismultiplier": false,
      "astyle": {
        "asprecision": 2,
        "asdecimalpoint": ".",
        "ascommodityside": "L",
        "asdigitgroups": null,
        "ascommodityspaced": false
      }
    }
  ],
  "aparent_": "root",
  "aibalance": [
    {
      "aprice": {
        "tag": "NoPrice"
      },
      "aquantity": {
        "decimalMantissa": 13,
        "decimalPlaces": 0
      },
      "acommodity": "",
      "aismultiplier": false,
      "astyle": {
        "asprecision": 2,
        "asdecimalpoint": ".",
        "ascommodityside": "L",
        "asdigitgroups": null,
        "ascommodityspaced": false
      }
    }
  ],
  "aname": "BTC",
  "aboring": false,
  "asubs": [],
  "asubs_": []
}
@simonmichael

This comment has been minimized.

Copy link
Owner

simonmichael commented Mar 9, 2019

Thanks for the report. That does seem wrong. Here's some related code: https://github.com/simonmichael/hledger/blob/master/hledger-web/Hledger/Web/Json.hs#L82

@real-dam

This comment has been minimized.

Copy link
Author

real-dam commented Mar 9, 2019

Well, the intention from the comments is clear. The "only the name of the parent" thing seems not to work, though. Even if it worked (aparent_="Crypto"), it wouldn't help the potential consumers, because it won't be enough to determine the full account name (and from there - the exact position of the account in the account tree).

What would help is either supplying the full account name (Assets:Crypto:BTC) in aname or another field, or full parent account name (Assets:Crypto) somewhere,

@simonmichael

This comment has been minimized.

Copy link
Owner

simonmichael commented Mar 9, 2019

Ah, I see what's going on. The account names on demo.hledger.org are confusing. That is actually the top-level account BTC.

/accounts is returning top-level accounts only. I guess the idea was that these would include their children.

And despite that code comment, I'm not sure why we couldn't do that (return the actual children). It seems to work, eg with sample.journal:

$ curl -s http://127.0.0.1:5000/accounts | ppjson
[
    {
        "aboring": false,
        "aebalance": [],
        "aibalance": [
            {
                "acommodity": "$",
                "aismultiplier": false,
                "aprice": {
                    "tag": "NoPrice"
                },
                "aquantity": {
                    "decimalMantissa": -1,
                    "decimalPlaces": 0
                },
                "astyle": {
                    "ascommodityside": "L",
                    "ascommodityspaced": false,
                    "asdecimalpoint": ".",
                    "asdigitgroups": null,
                    "asprecision": 0
                }
            }
        ],
        "aname": "assets",
        "anumpostings": 0,
        "aparent_": "root",
        "asubs": [
            {
                "aboring": false,
                "aebalance": [],
                "aibalance": [
                    {
                        "acommodity": "$",
                        "aismultiplier": false,
                        "aprice": {
                            "tag": "NoPrice"
                        },
                        "aquantity": {
                            "decimalMantissa": 1,
                            "decimalPlaces": 0
                        },
                        "astyle": {
                            "ascommodityside": "L",
                            "ascommodityspaced": false,
                            "asdecimalpoint": ".",
                            "asdigitgroups": null,
                            "asprecision": 0
                        }
                    }
                ],
                "aname": "assets:bank",
                "anumpostings": 0,
                "aparent_": "assets",
                "asubs": [
                    {
                        "aboring": false,
                        "aebalance": [
                            {
                                "acommodity": "$",
                                "aismultiplier": false,
                                "aprice": {
                                    "tag": "NoPrice"
                                },
                                "aquantity": {
                                    "decimalMantissa": 0,
                                    "decimalPlaces": 0
                                },
                                "astyle": {
                                    "ascommodityside": "L",
                                    "ascommodityspaced": false,
                                    "asdecimalpoint": ".",
                                    "asdigitgroups": null,
                                    "asprecision": 0
                                }
                            }
                        ],
                        "aibalance": [
                            {
                                "acommodity": "$",
                                "aismultiplier": false,
                                "aprice": {
                                    "tag": "NoPrice"
                                },
                                "aquantity": {
                                    "decimalMantissa": 0,
                                    "decimalPlaces": 0
                                },
                                "astyle": {
                                    "ascommodityside": "L",
                                    "ascommodityspaced": false,
                                    "asdecimalpoint": ".",
                                    "asdigitgroups": null,
                                    "asprecision": 0
                                }
                            }
                        ],
                        "aname": "assets:bank:checking",
                        "anumpostings": 4,
                        "aparent_": "assets:bank",
                        "asubs": [],
                        "asubs_": []
                    },
                    {
                        "aboring": false,
                        "aebalance": [
                            {
                                "acommodity": "$",
                                "aismultiplier": false,
                                "aprice": {
                                    "tag": "NoPrice"
                                },
                                "aquantity": {
                                    "decimalMantissa": 1,
                                    "decimalPlaces": 0
                                },
                                "astyle": {
                                    "ascommodityside": "L",
                                    "ascommodityspaced": false,
                                    "asdecimalpoint": ".",
                                    "asdigitgroups": null,
                                    "asprecision": 0
                                }
                            }
                        ],
                        "aibalance": [
                            {
                                "acommodity": "$",
                                "aismultiplier": false,
                                "aprice": {
                                    "tag": "NoPrice"
                                },
                                "aquantity": {
                                    "decimalMantissa": 1,
                                    "decimalPlaces": 0
                                },
                                "astyle": {
                                    "ascommodityside": "L",
                                    "ascommodityspaced": false,
                                    "asdecimalpoint": ".",
                                    "asdigitgroups": null,
                                    "asprecision": 0
                                }
                            }
                        ],
                        "aname": "assets:bank:saving",
                        "anumpostings": 1,
                        "aparent_": "assets:bank",
                        "asubs": [],
                        "asubs_": []
                    }
                ],
                "asubs_": [
                    "assets:bank:checking",
                    "assets:bank:saving"
                ]
            },
            {
                "aboring": false,
                "aebalance": [
                    {
                        "acommodity": "$",
                        "aismultiplier": false,
                        "aprice": {
                            "tag": "NoPrice"
                        },
                        "aquantity": {
                            "decimalMantissa": -2,
                            "decimalPlaces": 0
                        },
                        "astyle": {
                            "ascommodityside": "L",
                            "ascommodityspaced": false,
                            "asdecimalpoint": ".",
                            "asdigitgroups": null,
                            "asprecision": 0
                        }
                    }
                ],
                "aibalance": [
                    {
                        "acommodity": "$",
                        "aismultiplier": false,
                        "aprice": {
                            "tag": "NoPrice"
                        },
                        "aquantity": {
                            "decimalMantissa": -2,
                            "decimalPlaces": 0
                        },
                        "astyle": {
                            "ascommodityside": "L",
                            "ascommodityspaced": false,
                            "asdecimalpoint": ".",
                            "asdigitgroups": null,
                            "asprecision": 0
                        }
                    }
                ],
                "aname": "assets:cash",
                "anumpostings": 1,
                "aparent_": "assets",
                "asubs": [],
                "asubs_": []
            }
        ],
        "asubs_": [
            "assets:bank",
            "assets:cash"
        ]
    },
    {
        "aboring": false,
        "aebalance": [],
        "aibalance": [
            {
                "acommodity": "$",
                "aismultiplier": false,
                "aprice": {
                    "tag": "NoPrice"
                },
                "aquantity": {
                    "decimalMantissa": 2,
                    "decimalPlaces": 0
                },
                "astyle": {
                    "ascommodityside": "L",
                    "ascommodityspaced": false,
                    "asdecimalpoint": ".",
                    "asdigitgroups": null,
                    "asprecision": 0
                }
            }
        ],
        "aname": "expenses",
        "anumpostings": 0,
        "aparent_": "root",
        "asubs": [
            {
                "aboring": false,
                "aebalance": [
                    {
                        "acommodity": "$",
                        "aismultiplier": false,
                        "aprice": {
                            "tag": "NoPrice"
                        },
                        "aquantity": {
                            "decimalMantissa": 1,
                            "decimalPlaces": 0
                        },
                        "astyle": {
                            "ascommodityside": "L",
                            "ascommodityspaced": false,
                            "asdecimalpoint": ".",
                            "asdigitgroups": null,
                            "asprecision": 0
                        }
                    }
                ],
                "aibalance": [
                    {
                        "acommodity": "$",
                        "aismultiplier": false,
                        "aprice": {
                            "tag": "NoPrice"
                        },
                        "aquantity": {
                            "decimalMantissa": 1,
                            "decimalPlaces": 0
                        },
                        "astyle": {
                            "ascommodityside": "L",
                            "ascommodityspaced": false,
                            "asdecimalpoint": ".",
                            "asdigitgroups": null,
                            "asprecision": 0
                        }
                    }
                ],
                "aname": "expenses:food",
                "anumpostings": 1,
                "aparent_": "expenses",
                "asubs": [],
                "asubs_": []
            },
            {
                "aboring": false,
                "aebalance": [
                    {
                        "acommodity": "$",
                        "aismultiplier": false,
                        "aprice": {
                            "tag": "NoPrice"
                        },
                        "aquantity": {
                            "decimalMantissa": 1,
                            "decimalPlaces": 0
                        },
                        "astyle": {
                            "ascommodityside": "L",
                            "ascommodityspaced": false,
                            "asdecimalpoint": ".",
                            "asdigitgroups": null,
                            "asprecision": 0
                        }
                    }
                ],
                "aibalance": [
                    {
                        "acommodity": "$",
                        "aismultiplier": false,
                        "aprice": {
                            "tag": "NoPrice"
                        },
                        "aquantity": {
                            "decimalMantissa": 1,
                            "decimalPlaces": 0
                        },
                        "astyle": {
                            "ascommodityside": "L",
                            "ascommodityspaced": false,
                            "asdecimalpoint": ".",
                            "asdigitgroups": null,
                            "asprecision": 0
                        }
                    }
                ],
                "aname": "expenses:supplies",
                "anumpostings": 1,
                "aparent_": "expenses",
                "asubs": [],
                "asubs_": []
            }
        ],
        "asubs_": [
            "expenses:food",
            "expenses:supplies"
        ]
    },
    {
        "aboring": false,
        "aebalance": [],
        "aibalance": [
            {
                "acommodity": "$",
                "aismultiplier": false,
                "aprice": {
                    "tag": "NoPrice"
                },
                "aquantity": {
                    "decimalMantissa": -2,
                    "decimalPlaces": 0
                },
                "astyle": {
                    "ascommodityside": "L",
                    "ascommodityspaced": false,
                    "asdecimalpoint": ".",
                    "asdigitgroups": null,
                    "asprecision": 0
                }
            }
        ],
        "aname": "income",
        "anumpostings": 0,
        "aparent_": "root",
        "asubs": [
            {
                "aboring": false,
                "aebalance": [
                    {
                        "acommodity": "$",
                        "aismultiplier": false,
                        "aprice": {
                            "tag": "NoPrice"
                        },
                        "aquantity": {
                            "decimalMantissa": -1,
                            "decimalPlaces": 0
                        },
                        "astyle": {
                            "ascommodityside": "L",
                            "ascommodityspaced": false,
                            "asdecimalpoint": ".",
                            "asdigitgroups": null,
                            "asprecision": 0
                        }
                    }
                ],
                "aibalance": [
                    {
                        "acommodity": "$",
                        "aismultiplier": false,
                        "aprice": {
                            "tag": "NoPrice"
                        },
                        "aquantity": {
                            "decimalMantissa": -1,
                            "decimalPlaces": 0
                        },
                        "astyle": {
                            "ascommodityside": "L",
                            "ascommodityspaced": false,
                            "asdecimalpoint": ".",
                            "asdigitgroups": null,
                            "asprecision": 0
                        }
                    }
                ],
                "aname": "income:gifts",
                "anumpostings": 1,
                "aparent_": "income",
                "asubs": [],
                "asubs_": []
            },
            {
                "aboring": false,
                "aebalance": [
                    {
                        "acommodity": "$",
                        "aismultiplier": false,
                        "aprice": {
                            "tag": "NoPrice"
                        },
                        "aquantity": {
                            "decimalMantissa": -1,
                            "decimalPlaces": 0
                        },
                        "astyle": {
                            "ascommodityside": "L",
                            "ascommodityspaced": false,
                            "asdecimalpoint": ".",
                            "asdigitgroups": null,
                            "asprecision": 0
                        }
                    }
                ],
                "aibalance": [
                    {
                        "acommodity": "$",
                        "aismultiplier": false,
                        "aprice": {
                            "tag": "NoPrice"
                        },
                        "aquantity": {
                            "decimalMantissa": -1,
                            "decimalPlaces": 0
                        },
                        "astyle": {
                            "ascommodityside": "L",
                            "ascommodityspaced": false,
                            "asdecimalpoint": ".",
                            "asdigitgroups": null,
                            "asprecision": 0
                        }
                    }
                ],
                "aname": "income:salary",
                "anumpostings": 1,
                "aparent_": "income",
                "asubs": [],
                "asubs_": []
            }
        ],
        "asubs_": [
            "income:gifts",
            "income:salary"
        ]
    },
    {
        "aboring": false,
        "aebalance": [],
        "aibalance": [
            {
                "acommodity": "$",
                "aismultiplier": false,
                "aprice": {
                    "tag": "NoPrice"
                },
                "aquantity": {
                    "decimalMantissa": 1,
                    "decimalPlaces": 0
                },
                "astyle": {
                    "ascommodityside": "L",
                    "ascommodityspaced": false,
                    "asdecimalpoint": ".",
                    "asdigitgroups": null,
                    "asprecision": 0
                }
            }
        ],
        "aname": "liabilities",
        "anumpostings": 0,
        "aparent_": "root",
        "asubs": [
            {
                "aboring": false,
                "aebalance": [
                    {
                        "acommodity": "$",
                        "aismultiplier": false,
                        "aprice": {
                            "tag": "NoPrice"
                        },
                        "aquantity": {
                            "decimalMantissa": 1,
                            "decimalPlaces": 0
                        },
                        "astyle": {
                            "ascommodityside": "L",
                            "ascommodityspaced": false,
                            "asdecimalpoint": ".",
                            "asdigitgroups": null,
                            "asprecision": 0
                        }
                    }
                ],
                "aibalance": [
                    {
                        "acommodity": "$",
                        "aismultiplier": false,
                        "aprice": {
                            "tag": "NoPrice"
                        },
                        "aquantity": {
                            "decimalMantissa": 1,
                            "decimalPlaces": 0
                        },
                        "astyle": {
                            "ascommodityside": "L",
                            "ascommodityspaced": false,
                            "asdecimalpoint": ".",
                            "asdigitgroups": null,
                            "asprecision": 0
                        }
                    }
                ],
                "aname": "liabilities:debts",
                "anumpostings": 1,
                "aparent_": "liabilities",
                "asubs": [],
                "asubs_": []
            }
        ],
        "asubs_": [
            "liabilities:debts"
        ]
    }
]

Or is it more usable to return a flat list ?

@simonmichael simonmichael changed the title /accounts API: all acounts have `root` as parent /accounts API: returns only top-level accounts Mar 9, 2019

simonmichael added a commit that referenced this issue Mar 9, 2019

simonmichael added a commit that referenced this issue Mar 9, 2019

web: /accounts: return all accounts, not just top-level ones (#985)
Accounts are returned as a flat list, in tree order, with asubs fields
empty.
@simonmichael

This comment has been minimized.

Copy link
Owner

simonmichael commented Mar 10, 2019

I think a flat list. And ideally if hledger is parsing Accounts from json, it would reconstruct the parent-child references (currently it doesn't).

I've updated master and demo.hledger.org to return all accounts in tree order. Thanks for the report.

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.