Postfix currency symbol formatting becomes incorrect #276

Closed
greyson opened this Issue Jul 30, 2015 · 2 comments

Projects

None yet

2 participants

@greyson
greyson commented Jul 30, 2015

This is weird, and I'm surprised not to find it already reported.

I typically use post-fix notation for even normal currencies (I have several that I track, so it's easier to be able to type them without remembering special key sequences) -- hence the problem. See the journal file below (anonymized, stripped to the bare minimum -- problem does not manifest if any one of the three transactions below are removed.)

Note the summary balance of the "Asset" account.

    ; Example of a journal which produced odd output.

    D 1,000.00 USD
    ; ^^ Note the default format -- present or otherwise, this should
    ;    govern the formatting of the output. Present or otherwise, it does
    ;    not change the output.

    ;; EXPECTED OUTPUT:
    ;          553.04 USD  Asset
    ;          389.04 USD    Bank:Checking
    ;          164.00 USD    Cash
    ;         -553.04 USD  Equity:Opening Balance
    ;--------------------
    ;                   0

    ;; ACTUAL OUTPUT
    ;           USD553.04  Asset
    ;          389.04 USD    Bank:Checking
    ;          164.00 USD    Cash
    ;         -553.04 USD  Equity:Opening Balance
    ;--------------------
    ;                   0

    ; Note that this is the output with, or without, the default
    ; formatting setting.

    2015/01/01 Opening balance (USD)
      Equity:Opening Balance
      Asset:Cash            164.00 USD
      Asset:Bank:Savings    389.04 USD

    2015/07/20 Anonymous account closure
      Asset:Bank:Savings   -389.04 USD ; closing account
      Asset:Receivables     389.04 USD

    2015/07/30 ! Anonymous check receiver
      Asset:Receivables    -389.04 USD
      Asset:Bank:Checking   389.04 USD

For reference, I am using hledger version 0.26 on Arch Linux installed with cabal (rather than AUR or some such)

It seems that once such a combination of transactions is placed, the formatting is irrevocably changed to prefix notation (which is much less readable when using currency codes) no matter what other transactions are added or removed.

@greyson
greyson commented Jul 30, 2015

Correction to the above;
This bug seems to manifest only when the receivables have been zero'd out. If there is still a balance there, then balance displays the total for Asset correctly.

Also seems to be related to Receivables being a sub-account of Asset since moving it to the top level causes correct formatting again.

@simonmichael
Owner

Thanks for this detailed bug report. I think this is quite likely to be the same issue as #230 - a corner case in our amount arithmetic drops the custom display style information. This needs to be fixed.

@simonmichael simonmichael added this to the 1.0 milestone Sep 2, 2015
@simonmichael simonmichael changed the title from BUG: Postfix formatting becomes incorrect to Postfix currency symbol formatting becomes incorrect Sep 2, 2015
@simonmichael simonmichael added a commit that referenced 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