Skip to content

transaction balancing with a balance assignment not using costs #2039

Closed

Description

@simonmichael

Reported by Rik Snel on the mail list:

RS:

While I was sorting this all out, I think I may have
stumbled on a bug regarding a three commodity trade where the prices are
specified with @@.

Here is a minimal example, note that the last posting only has a
balance assertion:

2023/01/02 * Trade
        Assets                  AAA-1.1 @@ CCC 2
        Assets                  BBB-1.2 @@ CCC 3
        Expenses:Fees           CCC 0.1
        Assets                  = CCC 4.9

hledger says:

hledger: Error: /home/user/journal:1-5:
1 | 2023-01-02 * Trade
  |     Assets                AAA-1.1
  |     Assets                BBB-1.2
  |     Expenses:Fees         CCC 0.1
  |     Assets                CCC 4.9 = CCC 4.9

Consider adjusting this entry's amounts, adding missing postings,
or recording conversion price(s) with @, @@ or equity postings.

SM:

That's an interesting example. The implicit last amount is constrained in two ways:

  1. by the balance assignment (it must be the amount that brings Assets's CCC balance to 4.9)

  2. and by transaction balancing (it must be the amount that brings AAA -1.1 @@ CCC 2 + BBB -1.2 @@ CCC 3 + CCC 0.1 to 0).

Ledger interprets the transaction this way:

$ ledger -f a.j print
2023/01/02 * Trade
    Assets                                   AAA-1.1 @@ CCC 2.0
    Assets                                   BBB-1.2 @@ CCC 3.0
    Expenses:Fees                            CCC 0.1
    Assets                                   CCC 4.9 = CCC 4.9

and as you say, hledger accepts this interpretation - if it's given with all amounts explicit.

Is transaction balancing supposed to balance costs, ie convert all amounts to cost before balancing ? I never quite thought of it that way, and it isn't spelled out at https://hledger.org/dev/hledger.html#costs or in Ledger docs, but yes, I think that is the customary behaviour.

So the interpretation above is correct, and yes, this does seem like a hledger bug. Also, the actual error message includes this info which seems like it should mention the costs, instead:

The real postings' sum should be 0 but is: AAA-1.1, BBB-1.2, CCC 5.0

Activity

  1. added
    A-BUGSomething wrong, confusing or sub-standard in the software, docs, or user experience.
    journalThe journal file format, and its features.
    on May 27, 2023
  2. added a commit that references this issue on May 27, 2023
    d19d866
  3. changed the title [-]transaction balancing with a balance assignment does not use costs[/-] [+]transaction balancing with a balance assignment not using costs[/+] on May 27, 2023
  4. simonmichael commented on Jun 1, 2023

    @simonmichael
    MemberAuthor

    Was this a duplicate of #2038 ? I think so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-BUGSomething wrong, confusing or sub-standard in the software, docs, or user experience.journalThe journal file format, and its features.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions