ledger2beancount
ledger2beancount copied to clipboard
Multiple assertions for one day
Hi, I have a ledger file where most transactions have a balance assertion. After conversion, there may be multiple assertions for the same day which causes some trouble.
The following is an example:
2018/03/29 * test1
equity:opening AUD -100
assets:bank AUD 100 = AUD 100
2018/03/29 * test2
expenses:cash AUD 20
assets:bank AUD -20 = AUD 80
After conversion, I get
;----------------------------------------------------------------------
; ledger2beancount conversion notes:
;
; - Account assets:bank renamed to Assets:Bank
; - Account equity:opening renamed to Equity:Opening
; - Account expenses:cash renamed to Expenses:Cash
;----------------------------------------------------------------------
1970-01-01 open Assets:Bank
1970-01-01 open Equity:Opening
1970-01-01 open Expenses:Cash
1970-01-01 commodity AUD
2018-03-29 * "test"
Equity:Opening -100 AUD
Assets:Bank 100 AUD
2018-03-30 balance Assets:Bank 100 AUD
2018-03-29 * "test"
Expenses:Cash 20 AUD
Assets:Bank -20 AUD
2018-03-30 balance Assets:Bank 80 AUD
bean-check reports:
/home/lbs/code/test/test.beancount:19: Balance failed for 'Assets:Bank': expected 100 AUD != accumulated 80 AUD (20 too little)
2018-03-30 balance Assets:Bank 100 AUD
/home/lbs/code/test/test.beancount:25: Duplicate balance assertion with different amounts
2018-03-30 balance Assets:Bank 80 AUD
version: ledger2beancount 2.6
Unfortunately, this is an incompatibility between ledger and beancount. Assertions / balance checks work in a different way.
This is covered in the manual:
First, beancount evaluates balance assertions at the beginning of the day whereas ledger evaluates them at the end of the day (up to ledger 3.1.1) or at the end of the transaction (newer versions of ledger). Therefore, we schedule the balance assertion for the day after the original transaction. This assumes that there are no other transactions on the same day that change the balance again for this account.
see "Balance assertions and assignments" in guide.md
Having said that, I'll check if ledger2beancount can avoid creating two balance checks for the same account on the same day, maybe with a conversion note about this issue.
Thanks. I had read the doc you mentioned and understood why this happened. In my case, I have thousands of errors after conversion, so I have to delete all the balance checks to make the file usable. It would be nice if the tool can deal with it.
It would be nice if the tool can deal with it.
What would you suggest? Skipping the balance checks and generating a warning?
Ideally, I would hope the checks being merged and produce one balance check for one day, so the original data are preserved as much as possible.
Implementation-wise, since ledger requires the transactions to be in the correct order, would it make sense to only keep the last assertion of a day?
Unfortunately, the current code doesn't make it easy to implement this but I'll take a look.
I'm on vacation at the moment but I'll try to look soon.
I haven't had time to look into this more, although I've solidified my impression that this would require big changes.
In the meantime, I suggest you use a workaround like:
./bin/ledger2beancount foo.ledger | grep -v "^[0-9]...-..-.. balance "
Thanks. Yeah I've removed the balance checks as a workaround.
Sorry, I won't have time to work on this in the near future.
+1
I also ran into this issue.
Sorry that I still haven't fixed this issue. I remember exactly where I was on vacation when it was filed. Long time.
I actually thought about this issue a week or two ago and I think I know how to solve it. I'd like to fix it this year but I have urgent work so this seems unlikely. I'll try to get it done soon, though.
@girishso you can use the workaround for now:
./bin/ledger2beancount foo.ledger | grep -v "^[0-9]...-..-.. balance "