assert an account's amount

65 views
Skip to first unread message

Randy Josleyn

unread,
Apr 7, 2020, 12:48:41 AM4/7/20
to ledge...@googlegroups.com
Hi list!

I'd like to use the `assert` directive to do a balance assertion of an account after `include`ing a journal file. I can't add the balance assertion to the included journal itself. I tried something like this:

assert amount account(assets:checking) == 27585.33 CNY

It just says that the assertion failed, which I'm sure is because I haven't understood how to use value expressions.

I read the documentation and noted that in section 11.1.1, there's a variable labelled "a" which says "... the balance of an account, without considering children". I tried to use that, but ledger returned "unknown identifier".

I realized I could just add a transaction that assigns the balance of assets:checking, but that doesn't seem like the best way to do it.

Does anyone have any suggestions on how to assert an account's balance with `assert` or in some other way?

Thanks!


Randy
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Randy Josleyn

unread,
Apr 7, 2020, 12:48:48 AM4/7/20
to ledge...@googlegroups.com

Taylor R Campbell

unread,
Apr 7, 2020, 12:51:35 AM4/7/20
to ledge...@googlegroups.com
> Date: Tue, 07 Apr 2020 12:47:37 +0800
> From: Randy Josleyn <randy....@gmail.com>
>
> I realized I could just add a transaction that assigns the balance
> of assets:checking, but that doesn't seem like the best way to do
> it.

This is exactly what I do. Why wouldn't it be the best way?

2020-04-01 Balance assertion
Assets:Checking = 123.00 USD

Martin Michlmayr

unread,
Apr 7, 2020, 12:59:28 AM4/7/20
to ledge...@googlegroups.com
* Randy Josleyn <randy....@gmail.com> [2020-04-07 12:47]:
> I'd like to use the `assert` directive to do a balance assertion of
> an account after `include`ing a journal file. I can't add the
> balance assertion to the included journal itself. I tried something
> like this:
>
> assert amount account(assets:checking) == 27585.33 CNY

Try:

assert account("assets:checking").amount == 27585.33 CNY

--
Martin Michlmayr
https://www.cyrius.com/

Randy Josleyn

unread,
Apr 7, 2020, 1:09:59 AM4/7/20
to ledge...@googlegroups.com, Taylor R Campbell
Hi Taylor,

I knew someone one say this as soon as I hit send :)

It does seem a little simpler than what I was trying to do. My beef with that is that it's not *really* a transaction, so I don't want to write it as one. That's really a minor reason.

What I did find is that if you have a default account set and the balance assignment is incorrect, the difference will end up in the default account instead of causing an error. That might actually be a useful side affect if you set the default account as something noticeable like "FAILED ASSERTION" or something. It would show up in your balance report and so on and still let you see the current state of your accounts.

Thanks for your response!

-- 
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 ledger-cli+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ledger-cli/20200407045133.ACA4C60A44%40jupiter.mumble.net.

Randy Josleyn

unread,
Apr 7, 2020, 1:12:24 AM4/7/20
to ledge...@googlegroups.com, Martin Michlmayr
Thanks, Martin. That works exactly as I wanted it to.


Randy

Michael Cooper

unread,
Apr 7, 2020, 1:27:49 AM4/7/20
to Ledger, Taylor R Campbell
To deal with the default account problem, I make the transaction explicitly 0. To deal with it not being a real transaction, I make it a virtual one. Together it looks like this

2020-04-06 * Reconcile
    [Assets:Checking]  $0 = $123.00
    [Assets:Savings]  $0 = $456.00

-Mythmon


--

---
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 ledger-cli+...@googlegroups.com.

psionl0

unread,
Apr 7, 2020, 2:31:47 AM4/7/20
to Ledger


On Tuesday, April 7, 2020 at 12:48:41 PM UTC+8, Randy wrote:
I'd like to use the `assert` directive to do a balance assertion of an account after `include`ing a journal file. I can't add the balance assertion to the included journal itself. I tried something like this:
..............

I realized I could just add a transaction that assigns the balance of assets:checking, but that doesn't seem like the best way to do it.

Why the need for an unbalanced transaction? It violates the bookkeeping principle and ignores the fact that the money for the checking account had to come from somewhere.

Just run ledger with the --equity option on the original journal file. If you want to change the balance of the checking account then decide which of the original accounts the money came from. If it came from none of them then include an extra account to source the change.
Reply all
Reply to author
Forward
0 new messages