Does beancount expect entries to be sorted by date?

64 views
Skip to first unread message

vijayvithal jahagirdar

unread,
Dec 14, 2021, 1:12:52 AM12/14/21
to Beancount
I have a script which does the following:

.....
entries.extend(calc_depreciation(entries))
balance= balance_by_account(entries date=datetime.date(2018,4,1) )
...
This results in a set of transactions like
2017 ....
2018 ....
2019 ...
2020 ...
2017 "depreciation For Asset class X"
2017 "depreciation For Asset class Y"

2018 "depreciation For Asset class X"
2018 "depreciation For Asset class Y"
...

The balance_by account is not seeing the depreciation entries because the for loop has the following exit condition

if date and entry.date >= date:


break

...

This assumes that the entries are sorted by date. Is the assumption correct? If yes what function should be called after entries.extend(calc_depreciation(entries)) to sort the entries?

Martin Blais

unread,
Dec 14, 2021, 1:57:26 AM12/14/21
to Beancount
A lot of the internal API functions do assume sorted inputs throughout (which is done by the parser, didn't really plan for a lot of API users TBH).
Not sure about this one, I'd have to review the source.
You can call beancount.core.data.sorted(entries) to do the same Beancount does internally.
Cheers,

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/05964e81-bbd0-494f-abc9-177610be2238n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages