Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple assertions for one day #256

Open
binshengliu opened this issue Sep 21, 2021 · 11 comments
Open

Multiple assertions for one day #256

binshengliu opened this issue Sep 21, 2021 · 11 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@binshengliu
Copy link

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

@tbm
Copy link
Collaborator

tbm commented Sep 21, 2021

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

@tbm
Copy link
Collaborator

tbm commented Sep 21, 2021

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.

@binshengliu
Copy link
Author

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.

@tbm tbm self-assigned this Sep 21, 2021
@tbm tbm added the enhancement New feature or request label Sep 21, 2021
@tbm tbm added this to the 2.7 milestone Sep 21, 2021
@tbm
Copy link
Collaborator

tbm commented Sep 21, 2021

It would be nice if the tool can deal with it.

What would you suggest? Skipping the balance checks and generating a warning?

@binshengliu
Copy link
Author

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?

@tbm
Copy link
Collaborator

tbm commented Sep 21, 2021

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.

@tbm
Copy link
Collaborator

tbm commented Sep 29, 2021

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 "

@binshengliu
Copy link
Author

Thanks. Yeah I've removed the balance checks as a workaround.

@tbm
Copy link
Collaborator

tbm commented Nov 19, 2021

Sorry, I won't have time to work on this in the near future.

@tbm tbm modified the milestones: 2.7, 3.0 Dec 14, 2022
@girishso
Copy link

girishso commented Dec 2, 2023

+1

I also ran into this issue.

@tbm
Copy link
Collaborator

tbm commented Dec 5, 2023

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 "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants