balance shows wrong amount display style with this journal #230

Closed
simonmichael opened this Issue Dec 29, 2014 · 6 comments

Projects

None yet

3 participants

@simonmichael
Owner

julm provided this test journal which provokes wrong output in a weirdly fragile way:

; simplified from julm's http://vpaste.net/qN238

D 1000,00€

1/1
      a:b         0

1/2
      a:1      4000,58  ; not starting this account name component with a digit fixes it
      a:D     -1000,58  ; lower-casing the D fixes it
      e       -3000

; hledger bal 
;             €3000.00  a     <------ not like the others
;             4000,58€    1
;            -1000,58€    D
;            -3000,00€  e
; --------------------
;                    0
@MarkusTeufelberger

Had the same issue with "USD" (first time it appears in a balance output, it gets prepended to the amount) but didn't get around to minimizing my ledgers to a test case yet...

@simonmichael
Owner

Since I see it wasn't mentioned here: it is a weakness in hledger's Amount arithmetic, there are some corner cases where the display style is not propagated correctly as amounts are combined. Julien Moutinho debugged and prepared a preliminary fix, which we need to rework.

@simonmichael simonmichael added this to the 1.0 milestone May 19, 2015
@thdox
thdox commented Aug 16, 2015

On top of what is described above, I have also obtained amounts in balance output that looks like the first line that I have added to example above. What i get is '€' commodity that is after the amount, as expected, but the decimal separator is a dot, and I would have expected a comma.

hledger bal 
           3000.00 €  z     <------ I also get this
            €3000.00  a     <------ not like the others
            4000,58€    1
           -1000,58€    D
           -3000,00€  e
--------------------
                   0
@simonmichael
Owner

Another symptom of the amount style being lost during amount arithmetic.

@simonmichael simonmichael modified the milestone: 1.0 Sep 2, 2015
@simonmichael
Owner

For the record, the above example is handled correctly by 0.23.3 but not by 0.24.

@simonmichael
Owner

40ab1e1 broke it.

@simonmichael simonmichael added a commit that closed this issue Sep 2, 2015
@simonmichael balance, etc: fix amount style loss (fixes #230, #276)
hledger-lib-0.24's "track the commodity of zero amounts when
possible (useful eg for hledger-web's multi-commodity charts)" preserved
the commodity when normalising a zero mixed amount, but not the amount
style. This showed up as occasionally incorrect amount style (commodity
symbol placement, decimal point character, etc.) in balance reports with
certain journals, like this:

  $ hledger bal
              €3000.00  a     <------ not using the canonical € style
              4000,58€    1
             -1000,58€    D
             -3000,00€  e
  --------------------
                     0

I thought this would require a big rewrite of amount arithmetic, but it
seems that just being a little more careful is enough. When normalising
a mixed amount containing multiple zeros in the same commodity, we now
preserve the last zero with its amount style, instead of replacing them
all with a new one.
b8d75b7
@simonmichael simonmichael modified the milestone: 1.0, 0.27 Sep 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment