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

transaction balancing with a balance assignment not using costs #2039

Closed
simonmichael opened this issue May 27, 2023 · 1 comment
Closed
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. journal The journal file format, and its features.

Comments

@simonmichael
Copy link
Owner

simonmichael commented May 27, 2023

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

@simonmichael simonmichael added A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. journal The journal file format, and its features. labels May 27, 2023
@simonmichael simonmichael changed the title transaction balancing with a balance assignment does not use costs transaction balancing with a balance assignment not using costs May 27, 2023
@simonmichael
Copy link
Owner Author

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

simonmichael added a commit that referenced this issue Jan 24, 2024
The code is a bit clearer, and it no longer discards amounts other
than the first when the running balance contains multiple costs.
(This bug was exposed by the fix for #2039).
simonmichael added a commit that referenced this issue Jan 24, 2024
The code is a bit clearer, and it no longer discards amounts other
than the first when the running balance contains multiple costs.
(This bug was exposed by the fix for #2039).
simonmichael added a commit that referenced this issue Jan 28, 2024
The code is a bit clearer, and it no longer discards amounts other
than the first when the running balance contains multiple costs.
(This bug was exposed by the fix for #2039).
adept pushed a commit to adept/hledger that referenced this issue Mar 8, 2024
…#2150)

The code is a bit clearer, and it no longer discards amounts other
than the first when the running balance contains multiple costs.
(This bug was exposed by the fix for simonmichael#2039).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. journal The journal file format, and its features.
Projects
None yet
Development

No branches or pull requests

1 participant