Repository navigation
transaction balancing with a balance assignment not using costs #2039
Description
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.9hledger 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.9Consider 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:
by the balance assignment (it must be the amount that brings Assets's CCC balance to 4.9)
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.9and 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
fix: use costs when balancing a txn with a balance assignment (fix #2039
[-]transaction balancing with a balance assignment does not use costs[/-][+]transaction balancing with a balance assignment not using costs[/+]simonmichael commentedon Jun 1, 2023
Was this a duplicate of #2038 ? I think so.
fix: check mixed-cost balances correctly again; cleanup (#2150)
fix: check mixed-cost balances correctly again; cleanup (#2150)
fix: check mixed-cost balances correctly again; cleanup (#2150)
fix: check mixed-cost balances correctly again; cleanup (hledgerorg#2150