That works. A few notes, real quick: - What you needed to do is just accumulate the postings. That's what the aggregate sum(posting) would do on the SELECT call. This accumulates in an Inventory object, using the rules of Inventories (e.g. for reducing lots against each other).
- What Jason referred to is the fact that if an inventory contains multiple positions, they get rendered horizontally by default. Adding FLATTEN at the end of your SQL query will render one line for each position. That works now. - The "holdings" code you're using works, but is to be obsoleted eventually. I had a special "holdings" package for computing such aggregates that was developed in days before the aggregation and booking was improved (an older, flawed method). Simply aggregating in an Inventory is now the simpler thing to do, and I'd like to eventually remove all that holdings code and replace it with simpler code from just beancount.core. (This is all just part of evolving software and the process.) Glad it worked and the API was simple to wrangle, On Thu, Jan 4, 2018 at 5:43 AM, Justus Pendleton <[email protected]> wrote: > On Thursday, January 4, 2018 at 2:16:16 PM UTC+7, Martin Blais wrote: >> >> But I'm not sure that bean-query is flexible enough to let me do what I >>> want here and only look at lots that still exist and are under water. So >>> I'm back to being stumped about how to proceed. Do I just need to drop into >>> python to get what I want? >>> >> >> I don't think you do, use select sum(position) and you should be on your >> way, if you want to drop to Python accumulate the Position instances to an >> Inventory and print those contents >> > > For the record, I gave up trying to do it in bean-query since my brain > apparently wasn't able to wrap around what I needed to. Doing this in > python was straightforward: > > > import beancount.loader > import beancount.core > from beancount.reports import holdings_reports > > import argparse > parser = argparse.ArgumentParser(description='List lots that have > negative value and are available for tax loss harvesting.') > parser.add_argument('bean') > parser.add_argument('-i', '--ignore-account', action='append') > args = parser.parse_args() > > TEMPLATE = '{currency}\t{number:,}\t{total_loss:,}\t\t({account})' > > entries, errors, options = beancount.loader.load_file(args.bean) > holdings, price_map = holdings_reports.get_assets_holdings(entries, > options) > print('\tunits\tloss\t\t\taccount') > print('--------------------------------------------------') > > for h in holdings: > if h.account in args.ignore_account: continue > if h.market_value < h.book_value: > print(TEMPLATE.format(total_loss = (h.market_value - > h.book_value), **h._asdict())) > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/beancount/46aed62b-7571-475e-b666-ac6f75d4417d%40googlegroups.com > <https://groups.google.com/d/msgid/beancount/46aed62b-7571-475e-b666-ac6f75d4417d%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/CAK21%2BhNZzztabNJz2W%2Bz2WSkoS0k%2BXKkzv1v60pvYsQcybWgiA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
