-
-
Notifications
You must be signed in to change notification settings - Fork 321
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
print should not strip commodity from zero amounts when it is specified in the journal #475
Comments
I guess this is a big deal and needs fixing...
% COLUMNS=80 hledger -f bug.journal reg
2017/01/01 assets $-5 $-5
expenses $5 0
2017/01/01 assets $5 $5
expenses $-5 0 % hledger -f bug.journal print | COLUMNS=80 hledger -f - reg
2017/01/01 assets $-5 $-5
expenses $5 0
2017/01/01 assets 0 0
expenses 0 0 |
Thanks for the example. Hmm, what exactly is going on here. Your file (1):
The expected balance report (2):
Output of print --explicit (3):
The balance report is unchanged, as expected (4):
Ordinary style-preserving print (5):
That changes the balance report to something different (6):
3 is actually incorrect, the assertions have been altered ( |
@simonmichael with |
If I understand you - no, the = 0 assertion is being processed normally and succeeding (because assertions test only a single commodity's balance, following Ledger. We've had some debate about this in the past). |
zsh% hledger -f - bal
2017/01/01
assets = $5
equity
2017/01/01
assets $0 = 0 Output:
I'd expect |
|
Update: a related print bug was fixed by commit 8bc67d5 above; the larger wishlist issue of making all commands show commodified zero remains open, and needs experimentation & testing. |
..and I for one do not yet fully understand the meaning of a "commodified zero". Is it a real thing ? |
In my mind, commodities like |
Is it something accountants recognise ? How urgent is this feature for hledger users ? I don't currently have any good use cases in mind (except for the hledger-web chart, where it helped show separate trend line for each commodity). |
I don't know about accountants, unfortunatly. For me, personally, what is important is that |
Ah! Well that (losing the commodity from assertions) was definitely a bug, I also noticed that and fixed it (see above). I thought this issue was about displaying zeroes with commodities generally, eg in reports. |
It seems like the currency is still lost from conversions, though: |
|
Looks like
-- | Get the string representation of an amount, based on its commodity's
--- display settings.
+-- display settings. Amounts which look like zero are rendered without sign or commodity.
showAmount :: Amount -> String
showAmount (Amount (Commodity {symbol="AUTO"}) _ _) = "" -- can appear in an error message
showAmount a@(Amount (Commodity {symbol=sym,side=side,spaced=spaced}) _ pri) =
case side of
- L -> printf "%s%s%s%s" sym' space quantity price
+ L -> printf "%s%s%s%s" sym' space quantity' price
- R -> printf "%s%s%s%s" quantity space sym' price
+ R -> printf "%s%s%s%s" quantity' space sym' price
where
- sym' = quoteCommoditySymbolIfNeeded sym
- space = if (spaced && not (null sym')) then " " else ""
- quantity = showAmount' a
+ quantity = showamountquantity a
+ displayingzero = null $ filter (`elem` "123456789") $ quantity
+ (quantity',sym') | displayingzero = ("0","")
+ | otherwise = (quantity,quoteCommoditySymbolIfNeeded sym)
+ space = if (not (null sym') && spaced) then " " else ""
price = maybe "" showPrice pri @simonmichael, do we still need this behavior? Maybe we can simply drop it and always render amounts with currencies and associated format style? |
Not sure! Let's try it. I would like come up with a clear theory/story for when showing commodity for zero makes sense. Otherwise there's the chance that with each little change like this we get deeper into a big destabilising/de-ledger-compatibilising task, the full size of which is not yet clear, and with the chance of having to rethink and backtrack on some of these decisions. |
So our current zero story is "zero is considered commodityless, and we display it without a commodity (except for a special case in hledger-web)". This is similar to Ledger. A new story could be, for example: "zero can have a commodity, eg because specified by a journal entry or inherited from summed amounts, and we preserve and display that." This change might be very easy, or it might raise new issues; testing required. What's the real problem it would solve ? I'm guessing the main goal is to firm up our new print story: "print preserves as much information from the journal as possible". @peti is this issue about that, or a general wish to track and report zero's commodity everywhere ? We should probably have separate issues for these. |
Yes, as I said, I don't care if currencies are dropped from zeros in the reports. My interest is in |
Aha. This was not clear to me. I'll update this issue's title. |
Ok. Please add reproducible examples of remaining cases where print strips commodity from zeros, as you find them. |
I'm using |
Thanks! There are two known things not preserved: 1. directives and 2. inter-transaction comments. I suppose those should be printed too. |
..which requires a little thought. Do you always want those in the output (print is used for reporting, small-scale reformatting, whole-journal transformation, and export), what if there are query options/arguments, etc. |
What about: directives and file-level comments are shown when you print with no filtering of any kind; otherwise only transactions are shown. |
Also, when does print show the directive for "automated" things (modified transactions, periodic transactions) and when does it show the modified/generated transactions instead. |
Ledger has (and I'll stop..):
|
hledger print
(and other commands) should not reduceEUR 0
to0
.[context: #471]
[note: some discussion below is from @simonmichael thinking this issue was about making all commands show commodified zero]
The text was updated successfully, but these errors were encountered: