On 02/24/2017 11:32 PM, John Wiegley wrote:
This is run whenever a transaction is parsed. It's current.journal->add_xact
that does the processing of automated transactions before adding it to the
journal.
I am not familiar with the code, but I tried debugging it anyways, as I use
automated transactions myself quite a bit.
It seems that indeed the automated transaction is processed correctly and
pushed to the account on the second post.
However, on the third xact, the assertion kicks in. Before the balance
assertion is thrown, in instance_t::parse_post, the value of the account is
calculated (line 1650):
value_t account_total
(post->account->amount().strip_annotations(keep_details_t()));
This calculates the value of the account by adding all the transactions. I
believe at this point, then automated transaction is not being considered.
I conclude that by seeing that in amount(), add_to_value() is called only once,
(just the explicit transaction, and not for the automated one probably). Here's
an excerpt from my gdb session:
Breakpoint 3, ledger::(anonymous namespace)::instance_t::parse_post
(this=0x7fffffffacb0, line=0x7db19c "Budget", len=17, account=0x7d0620,
xact=0x7e62b0, defer_expr=false) at
/home/yuval/software/ledger/src/textual.cc:1650
1650 (post->account->amount().strip_annotations(keep_details_t()));
(gdb) c
Continuing.
Breakpoint 4, ledger::post_t::add_to_value (this=0x7e40c0, value=..., expr=...)
at /home/yuval/software/ledger/src/post.cc:628
628 if (xdata_ && xdata_->has_flags(POST_EXT_COMPOUND)) {
(gdb)
Continuing.
Breakpoint 2, ledger::(anonymous namespace)::instance_t::parse_post
(this=0x7fffffffacb0, line=0x7db19c "Budget", len=17, account=0x7d0620,
xact=0x7e62b0, defer_expr=false) at
/home/yuval/software/ledger/src/textual.cc:1690
1690 amount_t tot = amt - diff;
(gdb) p account_total.as_amount().to_double()
$53 = 100
I could not fully drill down the values to print them in gdb, but I would
expect to see two calls to add_to_value(), and that the account_total would be
90 at this point. My guess is that the automated transaction is missing a flag.
Here's a debug run:
$ ./ledger --debug post -f /tmp/ledger.dat
0ms [INFO] Ledger starting
1ms [INFO] Parsing file "/home/yuval/.ledgerrc"
Ledger 3.1.2-20160801, the command-line accounting tool
Copyright (c) 2003-2016, John Wiegley. All rights reserved.
This program is made available under the terms of the BSD Public License.
See LICENSE file included with the distribution for details and disclaimer.
1ms [INFO] Parsing file "/tmp/ledger.dat"
3ms [DEBUG] line 14: account balance = $90
3ms [DEBUG] line 14: post amount = $90
3ms [DEBUG] line 14: diff = $0
3ms [DEBUG] line 15: account balance = $10
3ms [DEBUG] line 15: post amount = $10
3ms [DEBUG] line 15: diff = $0
4ms [DEBUG] line 16: account balance = $100
4ms [DEBUG] line 16: post amount = $90
4ms [DEBUG] line 16: diff = $-10
While parsing file "/tmp/ledger.dat", line 16:
While parsing posting:
Budget $0 = $90
^^^
Error: Balance assertion off by $-10 (expected to see $100)
4ms [INFO] Ledger ended
I used v3.1-567-g3a00e1cd, and the same file the OP gave in the top of the
thread. Here it is again:
= /Expense/
(Budget) -1
01/01 Paid
Assets $100
Income
(Budget) $100
01/02 Lunch
Expense $10
Assets
01/03 Assertions
Assets $0 = $90
Expense $0 = $10
Budget $0 = $90
--
---
You received this message because you are subscribed to the Google Groups "Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.