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

balance transactions with their amounts' precisions #1479

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Commits on Feb 19, 2021

  1. Configuration menu
    Copy the full SHA
    1f331cb View commit details
    Browse the repository at this point in the history
  2. use a transaction's amount precisions when balancing it (#1479)

    A surprising development in old behaviour: as a consequence of #931,
    print now shows amounts with all of their decimal places, so we had
    better balance transactions using all of those visible digits
    (so that hledger and a user will agree on whether it's balanced).
    
    So now when transaction balancing compares amounts to see if they look
    equal, it uses (for each commodity) the maximum precision seen in just
    that transaction's amounts - not the precision from the journal's
    commodity display styles.
    
    This makes it more localised - therefore simpler - and more robust,
    when print-ing transactions to be re-parsed by hledger (previously,
    print-ed transactions could be unparseable because they were dependent
    on commodity directives).
    
    However, the new behaviour can break existing journals, so we provide
    a `--balancing=exact|styled` option to select the new (default) or old
    balancing behaviour. (The old behaviour may not be *perfectly*
    replicated, but it's hopefully close enough to be unnoticeable.)
    This is intended as a temporary migration aid, hopefully to be removed
    eventually.
    
    In journalFinalise, applying commodity display styles to the journal's
    amounts is now done as a final step (after transaction balancing, not
    before), and only once (rather than twice when auto postings are
    enabled), and seems slightly more thorough (affecting some inferred
    amounts where it didn't before).
    
    As a consequence of this change, inferred unit transaction
    prices (which arise in a two-commodity transaction with 3+ postings,
    and can be seen with print -x) may in some cases be generated with a
    different (greater) precision than before. Specifically, it will now
    be the sum of the number of decimal places in the amounts being
    converted to and from. (Whereas before, it was.. something else.)
    Hopefully this will always be a suitable number of digits such that
    hledger's & users' calculation of balancedness will agree.
    
    Lib changes:
    
    Hledger.Data.Journal
    added:
    journalInferCommodityStyles
    journalInferAndApplyCommodityStyles
    removed:
    canonicalStyleFrom
    simonmichael committed Feb 19, 2021
    Configuration menu
    Copy the full SHA
    de73f55 View commit details
    Browse the repository at this point in the history
  3. WIP

    simonmichael committed Feb 19, 2021
    Configuration menu
    Copy the full SHA
    b6b0c85 View commit details
    Browse the repository at this point in the history