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

hledger print -X doesn't properly convert balance assertions/assignments #1429

Closed
aragaer opened this issue Dec 27, 2020 · 6 comments
Closed
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. docs Documentation-related. print

Comments

@aragaer
Copy link
Contributor

aragaer commented Dec 27, 2020

hledger print with -X option only converts changes but not asserions/assignments. Resulting output is not a correct entry. See an example below.

$ cat b
P 2020-12-28 A 2

2020-12-28
 assets  4 = 4
 income
$ hledger -f b print
2020-12-28
    assets               4 = 4
    income

$ hledger -f b print | hledger -f - bal
                   4  assets
                  -4  income
--------------------
                   0
$ hledger -f b print -X A
2020-12-28
    assets              A2 = 4
    income             A-2

$ hledger -f b print -X A | hledger -f - bal
hledger: balance assertion: "-" (line 2, column 28)
transaction:
2020-12-28
    assets              A2 = 4
    income             A-2

assertion details:
date:       2020-12-28
account:    assets
commodity:  
calculated: 0
asserted:   4
difference: 4
@aragaer aragaer added the A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. label Dec 27, 2020
@simonmichael
Copy link
Owner

simonmichael commented Dec 27, 2020

@aragaer thanks for the report!

Normally we expect print's output to be valid and parseable. There are a few cases where it may not be, and you are right, this is one of them. I feel that this may be one where an exception to that rule is justified. A balance assertion is a definite statement made by the user and I'm not sure it's right to be changing it in any way.

@aragaer
Copy link
Contributor Author

aragaer commented Dec 27, 2020

I was expecting that all amounts would be converted to the one specified, including the asserted one. However even without assertions there is a rounding problem when converted entries do not balance to zero.

@simonmichael
Copy link
Owner

Got an example of the rounding problem ? Feel free to open a separate issue for that.

@simonmichael
Copy link
Owner

simonmichael commented Dec 27, 2020

Re the balance assertion, perhaps we'll get some more opinions in coming days. Meanwhile..

We could automatically remove or comment balance assertions when using valuation with print. But balance assignments would remain problematic, I think.

We could provide a flag allowing the user to remove or comment balance assertions when they are getting in the way. Of course we already have -I/--ignore-assertions to ignore them when reading.

We should be guided by solving real-world problem(s). Has this come up for you as a real problem in practice yet ?

@aragaer
Copy link
Contributor Author

aragaer commented Dec 28, 2020

It was more like an attempt to work around the #1417 using hledger print -X piped into hledger -f - roi. Adding -I on the reading side fixes this problem but reveals the rounding problem. I will now create a separate issue for that one.

@simonmichael simonmichael added the docs Documentation-related. label Dec 28, 2020
@simonmichael
Copy link
Owner

We should update docs, which currently say "print's output is always a valid hledger journal." I've done that: https://hledger.org/hledger.html#print

Xitian9 pushed a commit to Xitian9/hledger that referenced this issue Jan 11, 2021
@simonmichael simonmichael added A-WISH Some kind of improvement request, hare-brained proposal, or plea. A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. and removed A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. A-WISH Some kind of improvement request, hare-brained proposal, or plea. labels Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. docs Documentation-related. print
Projects
None yet
Development

No branches or pull requests

2 participants