The behaviour of the total() function confused me a lot, it has non
idempotent side effects. Posting this here in case someone else comes to
this thread looking for info. I can't claim to fully understand what's
going on, but an assert in another ledger file that is parsed before it can
alter the result of the total() function, in practice eval
print( 'account("a").total') will show you the totals are summed but only
if they appear in different scopes. So I think it's safe to claim:
- You should have at most one assert on total in your ledger files
assert 'account("a").total' == 10
- You probably instead want to us amount, which does not have side effects
assert 'account("a").amount' == 10
If anyone else has a better understanding of what is going on, and why
multiple asserts can influence each other I would be very interested to
know.
-j
On Monday, November 19, 2012 at 11:59:47 PM UTC+1, unices wrote:
>
> Hi,
> I came across the same problem and got it partially working by
> using amount instead of total:
>
> % cat test.dat
> 2012/10/09 t
> a € 2
> b
>
> 2012/10/09 t
> a € 4
> b
>
> 2012/10/09 t
> c € 5
> a
>
> check account("a").amount == € 1
>
> 2012/10/09 t
> a:1 € 3
> z
>
> check account("a").amount == € 4
> check account("a:1").amount == € 3
>
> % ledger -f test.dat bal
> Warning: "test.dat", line 19: Check failed: account("a").amount == € 4
> € 4 a
> € 3 1
> € -6 b
> € 5 c
> € -3 z
> --------------------
> 0
>
> What I find furthermore interesting is how the account's
> total() and amount() develop during a register report.
> Is this behaviour intended? Is it correct?
> Or could this be a bug?
>
> %ledger -f test.dat reg --total 'account("a").total()'
> 09.10.2012 t a € 2
> € 2
> b € -2
> € 2
> 09.10.2012 t a € 4
> € 2 ; I'd expect € 6 here
> b € -4
> € 2
> 09.10.2012 t c € 5
> € 2
> a € -5
> € -3 ; I'd expect € 1 here
> 09.10.2012 t a:1 € 3
> € -3
> z € -3
> € -3
>
> %ledger -f test.dat reg --total 'account("a").amount()'
> 09.10.2012 t a € 2
> € 2
> b € -2
> € 2
> 09.10.2012 t a € 4
> € 2
> b € -4
> € 2
> 09.10.2012 t c € 5
> € 2
> a € -5
> € 2
> 09.10.2012 t a:1 € 3
> € 2
> z
>
> Alexis
>
--
---
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.